├── .gitignore
├── API_Examples.md
├── LICENSE
├── README.md
├── api
├── pom.xml
└── src
│ └── main
│ └── scala
│ └── bi
│ └── meteorite
│ └── core
│ └── api
│ ├── objects
│ ├── Event.scala
│ ├── MeteoriteNode.scala
│ ├── MeteoriteRole.scala
│ ├── MeteoriteUser.scala
│ └── UserList.scala
│ ├── persistence
│ ├── EventService.scala
│ └── UserService.scala
│ ├── repository
│ └── IRepositoryManager.scala
│ └── security
│ ├── AdminLoginService.scala
│ ├── IMeteoriteUser.scala
│ ├── IUserManagement.scala
│ ├── IUserManagementProvider.scala
│ ├── exceptions
│ ├── MeteoriteSecurityException.scala
│ └── TokenProviderException.scala
│ ├── rest
│ ├── UserAuthentication.scala
│ └── UserService.scala
│ └── tokenprovider
│ ├── IToken.scala
│ ├── InvalidTokenException.scala
│ └── TokenProvider.scala
├── features
├── pom.xml
└── src
│ └── main
│ └── feature
│ └── feature.xml
├── karaf
├── pom.xml
└── src
│ └── main
│ ├── karaf
│ └── assembly-property-edits.xml
│ └── resources
│ └── etc
│ ├── org.ops4j.datasource-eventslist.cfg
│ ├── org.ops4j.pax.url.mvn.cfg
│ └── system.properties
├── meteorite-core-itests
├── pom.xml
└── src
│ └── test
│ ├── java
│ └── bi
│ │ └── meteorite
│ │ ├── core
│ │ └── security
│ │ │ ├── TestSecurity.java
│ │ │ ├── TestUserAdmin.java
│ │ │ └── package-info.java
│ │ ├── package-info.java
│ │ └── util
│ │ ├── ITestBootstrap.java
│ │ └── package-info.java
│ └── resources
│ └── org.ops4j.datasource-users.cfg
├── meteorite-persistence
├── pom.xml
└── src
│ └── main
│ └── java
│ └── bi
│ └── meteorite
│ └── core
│ └── security
│ └── hibernate
│ ├── EventServiceImpl.java
│ ├── UserServiceImpl.java
│ └── package-info.java
├── model-scala
├── pom.xml
└── src
│ └── main
│ ├── resources
│ └── META-INF
│ │ └── persistence.xml
│ └── scala
│ └── bi
│ └── meteorite
│ └── objects
│ ├── EventImpl.scala
│ ├── RoleImpl.scala
│ └── UserImpl.scala
├── pom.xml
├── security-provider-scala
├── pom.xml
└── src
│ ├── main
│ ├── resources
│ │ └── OSGI-INF
│ │ │ └── blueprint
│ │ │ └── blueprint.xml
│ └── scala
│ │ └── bi
│ │ └── meteorite
│ │ └── core
│ │ └── security
│ │ ├── hibernate
│ │ └── DefaultUsers.scala
│ │ ├── jaas
│ │ ├── JaasLoginManager.scala
│ │ └── JaasUserManager.scala
│ │ └── tokenprovider
│ │ ├── CacheManagerTokenStore.scala
│ │ ├── CompositeClassLoader.scala
│ │ ├── Token.scala
│ │ ├── TokenProviderImpl.scala
│ │ ├── TokenStorageProvider.scala
│ │ └── TokenUtil.scala
│ └── test
│ └── java
│ └── bi
│ └── meteorite
│ └── core
│ └── security
│ └── jaas
│ ├── TestJaasLoginManager.java
│ ├── TestJaasUserManager.java
│ └── package-info.java
├── security-scala
├── pom.xml
└── src
│ └── main
│ ├── resources
│ └── OSGI-INF
│ │ └── blueprint
│ │ └── blueprint.xml
│ └── scala
│ └── bi
│ └── meteorite
│ └── core
│ └── security
│ ├── SecurityFilter.scala
│ ├── UserManager.scala
│ ├── authentication
│ ├── CustomHttpAuthenticationFaultHandler.scala
│ ├── CustomObjectMapper.scala
│ ├── TokenAuthenticationFeature.scala
│ ├── TokenJAASAuthenticationFilter.scala
│ └── TokenResponseFilter.scala
│ ├── authorization
│ ├── TokenAbstractAutorizingInInterceptor.scala
│ ├── TokenAuthorizingFilter.scala
│ └── TokenAuthorizingInterceptor.scala
│ └── rest
│ ├── UserAuthenticationImpl.scala
│ ├── UserServiceImpl.scala
│ └── objects
│ └── UserObj.scala
└── src
└── main
└── config
└── checkstyle
├── checker.xml
├── checkstyle-checker.xml
├── header.txt
└── suppressions.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | karaf/assembly/
2 | .clover
3 | target/
4 | **/target/
5 | pom.xml.tag
6 | pom.xml.releaseBackup
7 | pom.xml.versionsBackup
8 | pom.xml.next
9 | release.properties
10 | dependency-reduced-pom.xml
11 | buildNumber.properties
12 | .mvn/timing.properties
13 |
14 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
15 |
16 | *.iml
17 |
18 | ## Directory-based project format:
19 | .idea/
20 | # if you remove the above rule, at least ignore the following:
21 |
22 | # User-specific stuff:
23 | # .idea/workspace.xml
24 | # .idea/tasks.xml
25 | # .idea/dictionaries
26 |
27 | # Sensitive or high-churn files:
28 | # .idea/dataSources.ids
29 | # .idea/dataSources.xml
30 | # .idea/sqlDataSources.xml
31 | # .idea/dynamic.xml
32 | # .idea/uiDesigner.xml
33 |
34 | # Gradle:
35 | # .idea/gradle.xml
36 | # .idea/libraries
37 |
38 | # Mongo Explorer plugin:
39 | # .idea/mongoSettings.xml
40 |
41 | ## File-based project format:
42 | *.ipr
43 | *.iws
44 |
45 | ## Plugin-specific files:
46 |
47 | # IntelliJ
48 | /out/
49 |
50 | # mpeltonen/sbt-idea plugin
51 | .idea_modules/
52 |
53 | # JIRA plugin
54 | atlassian-ide-plugin.xml
55 |
56 | # Crashlytics plugin (for Android Studio and IntelliJ)
57 | com_crashlytics_export_strings.xml
58 | crashlytics.properties
59 | crashlytics-build.properties
60 |
--------------------------------------------------------------------------------
/API_Examples.md:
--------------------------------------------------------------------------------
1 | # API Examples
2 |
3 |
4 | ## Get Existing Users
5 |
6 | http://localhost:8181/cxf/rest/core/user
7 |
8 | Returns a string list of id's and usernames:
9 |
10 | [
11 | {
12 | "id":1,
13 | "username":"admin"
14 | },
15 | {
16 | "id":2,
17 | "username":"smith"
18 | }
19 | ]
20 |
21 | ## Add user (or update)
22 |
23 | To add a user to the platform you can POST the following object:
24 |
25 | {
26 | "@class": "bi.meteorite.core.security.rest.objects.UserObj",
27 | "username": "test2",
28 | "password": "test2",
29 | "orgId": 0,
30 | "email": "test@test.com",
31 | "roles": null
32 | }
33 |
34 | to http://localhost:8181/cxf/rest/core/user
35 |
36 | The @class property is mandatory to specify the concrete class that implements the interface used in the server API.
37 |
38 | To update include the user id.
39 |
40 | ## Update a user
41 |
42 | To add a user to the platform you can PUT the following object:
43 |
44 | {
45 | "@class": "bi.meteorite.core.security.rest.objects.UserObj",
46 | "username": "test2",
47 | "password": "test2",
48 | "orgId": 0,
49 | "email": "test@test.com",
50 | "roles": null,
51 | "id": 1
52 | }
53 |
54 | to http://localhost:8181/cxf/rest/core/user
55 |
56 | The @class property is mandatory to specify the concrete class that implements the interface used in the server API.
57 |
58 |
59 | ## Get User
60 |
61 | To get user details for a user:
62 |
63 | http://localhost:8181/cxf/rest/core/user/lookup/{id}
64 |
65 | id is the user id.
66 |
67 | {
68 | "@class":"bi.meteorite.objects.UserImpl",
69 | "id":1,
70 | "username":"admin",
71 | "password":"admin",
72 | "roles":[
73 | {
74 | "id":1,
75 | "role":"ROLE_ADMIN",
76 | "userId":null
77 | },
78 | {
79 | "id":2,
80 | "role":"ROLE_USER",
81 | "userId":null
82 | }
83 | ],
84 | "orgId":0,
85 | "email":null
86 | }
87 |
88 |
89 | ## Delete a User
90 |
91 | Send a DELETE to
92 | http://localhost:8181/cxf/rest/core/user/{id}
93 |
94 | and it will remove the user and associated roles.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # meteorite-core
2 | Core for Saiku and other stuff, provides interfaces for JCR and Security
3 |
4 | [API Examples](API_Examples.md)
5 |
6 | ## To build
7 |
8 | Check out and run
9 |
10 | mvn clean install
11 |
12 | to skip tests run
13 |
14 | mvn clean install -DskipTests
15 |
16 |
17 | ## To deploy:
18 |
19 | extract the meteorite-engine zip file from karaf/target and run
20 |
21 | ./bin/karaf
22 |
23 | or
24 |
25 | ./bin/karaf debug
26 |
27 | once started run
28 |
29 | feature:install meteorite-core-features
30 |
31 |
32 | ## To update modules over the wire:
33 |
34 | bundle:update id
35 |
36 | For example:
37 |
38 | bundle:update 294
39 |
40 | Or
41 |
42 | bundle:update bi.meteorite.core-api
43 | bundle:update bi.meteorite.core-model-scala
44 | bundle:update bi.meteorite.core-persistence
45 | bundle:update bi.meteorite.core-security-provider-scala
46 | bundle:update bi.meteorite.core-security-scala
47 | bundle:update bi.meteorite.ui-shared
48 | bundle:update bi.meteorite.ui
49 |
50 | ## To run a specific integration test:
51 |
52 | To run a specific test class run
53 |
54 | mvn clean install -Dtest=TestSecurity
55 |
56 | To run a specific test class method run
57 |
58 | mvn clean install -Dtest=TestSecurity#testNonAdminLockDown
59 |
60 |
--------------------------------------------------------------------------------
/api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | bi.meteorite
6 | core
7 | 1.0-SNAPSHOT
8 |
9 | meteorite-core-api
10 | 1.0-SNAPSHOT
11 | bundle
12 |
13 | Meteorite Core API Package
14 | The API and interfaces for the Meteorite Core platform
15 |
16 | ../
17 |
18 |
19 |
20 | com.fasterxml.jackson.core
21 | jackson-annotations
22 | 2.6.2
23 |
24 |
25 | com.fasterxml.jackson.core
26 | jackson-annotations
27 | 2.6.2
28 |
29 |
30 | com.qmino
31 | miredot-annotations
32 | provided
33 | true
34 |
35 |
39 |
40 | javax.annotation
41 | javax.annotation-api
42 | 1.2
43 |
44 |
45 | javax.servlet
46 | servlet-api
47 |
48 |
49 | javax.ws.rs
50 | javax.ws.rs-api
51 | provided
52 |
53 |
54 | org.apache.cxf
55 | cxf-rt-rs-security-cors
56 |
57 |
58 | org.apache.karaf.jaas
59 | org.apache.karaf.jaas.modules
60 | provided
61 |
62 |
63 | org.scala-lang
64 | scala-library
65 |
66 |
67 |
68 |
69 |
70 |
71 | net.alchim31.maven
72 | scala-maven-plugin
73 | 3.2.1
74 |
75 | 2.11.7
76 |
77 |
78 |
79 |
80 | compile
81 | testCompile
82 |
83 |
84 |
85 |
86 |
87 | org.apache.felix
88 | maven-bundle-plugin
89 | 2.3.7
90 | true
91 |
92 |
93 | bi.meteorite.core.api.*
94 | com.fasterxml.jackson.annotation,javax.persistence,*
95 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/objects/Event.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.api.objects
17 |
18 | import java.util.Date
19 |
20 | /**
21 | * An Event Object For Audit Purposes.
22 | */
23 | trait Event {
24 | /**
25 | * Get the Event Id (set by the persistence manager)
26 | * @return the event ID
27 | */
28 | def getId: Long
29 |
30 | /**
31 | * Set the event ID.
32 | * @param id The ID number
33 | */
34 | def setId(id: Long)
35 |
36 | /**
37 | * Get the Event UUID.
38 | * @return A UUID
39 | */
40 | def getUuid: String
41 |
42 | /**
43 | * Set the Event UUID.
44 | * @param uuid The UUID String
45 | */
46 | def setUuid(uuid: String)
47 |
48 |
49 | /**
50 | * Get the triggering class.
51 | * @return The class name
52 | */
53 | def getClassName: String
54 |
55 | /**
56 | * Set the triggering class name.
57 | * @param className The class name.
58 | */
59 | def setClassName(className: String)
60 |
61 | /**
62 | * Get the event name.
63 | * @return The name of the event.
64 | */
65 | def getEventName: String
66 |
67 |
68 | /**
69 | * set the event name.
70 | * @param eventName The event name.
71 | */
72 | def setEventName(eventName: String)
73 |
74 | /**
75 | * Get any additional comment that was stored with the event.
76 | * @return The comment.
77 | */
78 | def getComment: String
79 |
80 | /**
81 | * Set an additional comment to add value to the event.
82 | * @param comment The comment string.
83 | */
84 | def setComment(comment: String)
85 |
86 | /**
87 | * Get the start date/time.
88 | * @return The start date & time.
89 | */
90 | def getStartDate: Date
91 |
92 | /**
93 | * Set the start date & time.
94 | * @param startDate
95 | */
96 | def setStartDate(startDate: Date)
97 |
98 |
99 | /**
100 | * Get the time the event finished.
101 | * @return The end date & time
102 | */
103 | def getEndDate: Date
104 |
105 | /**
106 | * Set the time the event ended.
107 | * @param endDate The end date & time.
108 | */
109 | def setEndDate(endDate: Date)
110 |
111 | /**
112 | * Get the duration in milliseconds.
113 | * @return The duration in milliseconds.
114 | */
115 | def getDuration: Long
116 |
117 | /**
118 | * Set the duration in milliseconds.
119 | * @param duration The duration.
120 | */
121 | def setDuration(duration: Long)
122 | }
123 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/objects/MeteoriteNode.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.api.objects
18 |
19 | /**
20 | * A Node for Persistence.
21 | */
22 | trait MeteoriteNode {
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/objects/MeteoriteRole.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.api.objects
17 |
18 | /**
19 | * An internal role for authentication.
20 | */
21 | trait MeteoriteRole {
22 | /**
23 | * Get the ID of the role (usually set by the persistence manager)
24 | * @return the ID.
25 | */
26 | def getId: Int
27 |
28 | /**
29 | * Set the ID
30 | * @param id the id.
31 | */
32 | def setId(id: Int)
33 |
34 | /**
35 | * Get the user object that is associated with the role.
36 | * @return A meteorite user object.
37 | */
38 | def getUserId: MeteoriteUser
39 |
40 | /**
41 | * Set the user associated with the role.
42 | * @param id the user.
43 | */
44 | def setUserId(id: MeteoriteUser)
45 |
46 | /**
47 | * Get the role name.
48 | * @return The role.
49 | */
50 | def getRole: String
51 |
52 | /**
53 | * Set the role name.
54 | * @param role
55 | */
56 | def setRole(role: String)
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/objects/MeteoriteUser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.api.objects
17 |
18 | import com.fasterxml.jackson.annotation.JsonTypeInfo
19 |
20 | /**
21 | * A user object for Meteorite core.
22 | */
23 | @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
24 | trait MeteoriteUser {
25 | /**
26 | * Get the username.
27 | *
28 | * @return the username
29 | */
30 | def getUsername: String
31 |
32 | /**
33 | * Set the username.
34 | *
35 | * @param username the username.
36 | */
37 | def setUsername(username: String)
38 |
39 | /**
40 | * Get the user password.
41 | *
42 | * @return the password.
43 | */
44 | def getPassword: String
45 |
46 | /**
47 | * Set the user password.
48 | *
49 | * @param password the password.
50 | */
51 | def setPassword(password: String)
52 |
53 | /**
54 | * Get an array of roles.
55 | *
56 | * @return an array of roles.
57 | */
58 | def getRoles: java.util.List[MeteoriteRole]
59 |
60 | /**
61 | * Set the roles.
62 | *
63 | * @param roles an array of roles.
64 | */
65 | def setRoles(roles: java.util.List[MeteoriteRole])
66 |
67 | /**
68 | * Get the user email address.
69 | *
70 | * @return the email address.
71 | */
72 | def getEmail: String
73 |
74 | /**
75 | * Set the email address.
76 | *
77 | * @param email the email address.
78 | */
79 | def setEmail(email: String)
80 |
81 | /**
82 | * Get the users unique id
83 | *
84 | * @return the id
85 | */
86 | def getId: Long
87 |
88 | /**
89 | * Set the users id.
90 | *
91 | * @param id the id.
92 | */
93 | def setId(id: Long)
94 |
95 | /**
96 | * Get the organization id.
97 | *
98 | * @return the org id.
99 | */
100 | def getOrgId: Int
101 |
102 | /**
103 | * Set the organization id.
104 | *
105 | * @param orgId the organization id.
106 | */
107 | def setOrgId(orgId: Int)
108 | }
109 |
110 |
111 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/objects/UserList.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.api.objects
17 |
18 | /**
19 | * Case Class object to return the usernames and associated user ID.
20 | */
21 | case class UserList(id: Long, username: String)
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/persistence/EventService.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.api.persistence
17 |
18 | import bi.meteorite.core.api.objects.Event
19 |
20 | /**
21 | * Interface for event persistence.
22 | */
23 | trait EventService {
24 | /**
25 | * Get the event by persistence managed ID
26 | * @param id
27 | * @return the event
28 | */
29 | def getEventById(id: String): Event
30 |
31 | /**
32 | * Get the event by the UUID set when the event was created.
33 | * @param uuid
34 | * @return The event
35 | */
36 | def getEventByUUID(uuid: String): Event
37 |
38 | /**
39 | * Get the event by the event name.
40 | * @param name
41 | * @return A List of events.
42 | */
43 | def getEventByEventName(name: String): List[Event]
44 |
45 | /**
46 | * Add an event.
47 | * @param event The event object.
48 | * @return The persisted event.
49 | */
50 | def addEvent(event: Event): Event
51 |
52 | /**
53 | * Get all events.
54 | * @return A list of events.
55 | */
56 | def getEvents: List[Event]
57 |
58 | /**
59 | * Update event.
60 | * @param event Update an already existing event.
61 | */
62 | def updateEvent(event: Event)
63 |
64 | /**
65 | * Delete event by persistence ID.
66 | * @param id the id of the event.
67 | */
68 | def deleteEventById(id: String)
69 |
70 | /**
71 | * Delete event by event UUID.
72 | * @param uuid the UUID of the event.
73 | */
74 | def deleteEventByUUID(uuid: String)
75 | }
76 |
77 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/persistence/UserService.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.api.persistence
18 |
19 | import bi.meteorite.core.api.objects.MeteoriteUser
20 | import bi.meteorite.core.api.objects.MeteoriteRole
21 |
22 | /**
23 | * Interface for persisting users.
24 | */
25 | trait UserService {
26 | /**
27 | * Update an existing user.
28 | * @param u the updated user object
29 | * @return The merged user.
30 | */
31 | def mergeUser(u: MeteoriteUser) : MeteoriteUser
32 |
33 | /**
34 | * Get a user by ID.
35 | * @param id The ID of the user object.
36 | * @return The MeteoriteUser.
37 | */
38 | def getUser(id: String): MeteoriteUser
39 |
40 | /**
41 | * Get user by ID.
42 | * @param id The Id of the user object.
43 | * @return The MeteoriteUser.
44 | */
45 | def getUser(id: Long): MeteoriteUser
46 |
47 | /**
48 | * Add a new MeteoriteUser.
49 | * @param user The MeteoriteUser object.
50 | * @return The persisted MeteoriteUser.
51 | */
52 | def addUser(user: MeteoriteUser): MeteoriteUser
53 |
54 | /**
55 | * Get all users.
56 | * @return A list of MeteoriteUsers
57 | */
58 | def getUsers: Iterable[MeteoriteUser]
59 |
60 | /**
61 | * Update a user.
62 | * @param user The MeteoriteUser to update.
63 | */
64 | def updateUser(user: MeteoriteUser)
65 |
66 | /**
67 | * Delete a user.
68 | * @param id The MeteoriteUser to delete.
69 | */
70 | def deleteUser(id: MeteoriteUser)
71 |
72 | /**
73 | * Delete User by ID.
74 | * @param id The ID of the remove you wish to remove.
75 | */
76 | def deleteUser(id: Long)
77 |
78 | /**
79 | * Add a role to an existing user.
80 | * @param r The role object
81 | * @return The persisted role.
82 | */
83 | def addRole(r: MeteoriteRole): MeteoriteRole
84 |
85 | /**
86 | * Delete a role assigned to a user.
87 | * @param id The role ID.
88 | */
89 | def deleteRole(id: String)
90 |
91 | /**
92 | * Get a role assigned to a user.
93 | * @param id The role name.
94 | * @return The MeteoriteRole.
95 | */
96 | def getRole(id: String): MeteoriteRole
97 | }
98 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/repository/IRepositoryManager.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.api.repository
17 |
18 | import bi.meteorite.core.api.objects.MeteoriteNode
19 | import bi.meteorite.core.api.objects.MeteoriteUser
20 |
21 | /**
22 | * Repository operations allowed from within Meteorite Core.
23 | */
24 | trait IRepositoryManager {
25 | /**
26 | * Initialize the repository.
27 | */
28 | def init
29 |
30 | /**
31 | * Start the repository.
32 | */
33 | def start
34 |
35 | /**
36 | * Stop the repository.
37 | */
38 | def stop
39 |
40 | /**
41 | * Add an object to the repository.
42 | *
43 | * @param node the file/folder object.
44 | */
45 | def addNode(node: MeteoriteNode)
46 |
47 | /**
48 | * Remove an object from the repository.
49 | *
50 | * @param node the file/folder object
51 | */
52 | def removeNode(node: MeteoriteNode)
53 |
54 | /**
55 | * Move an object within the repository.
56 | *
57 | * @param from from location.
58 | * @param to to location.
59 | * @param user the user performing the operation.
60 | */
61 | def moveNode(from: String, to: String, user: MeteoriteUser)
62 |
63 | /**
64 | * Copy an object within the repository.
65 | *
66 | * @param from from location.
67 | * @param to to location.
68 | * @param user the user performing the operation.
69 | */
70 | def copyNode(from: String, to: String, user: MeteoriteUser)
71 |
72 | /**
73 | * Remove the repository from the server.
74 | */
75 | def dropRepository
76 |
77 | /**
78 | * Export the repository to a file.
79 | *
80 | * @return the repository.
81 | */
82 | def exportRepository: Array[Byte]
83 |
84 | /**
85 | * Restore a backup.
86 | *
87 | * @param data the file.
88 | */
89 | def restoreResponsitory(data: Array[Byte])
90 |
91 | /**
92 | * Rollback an object to a previous version.
93 | *
94 | * @param node the node to rollback on.
95 | */
96 | def rollbackNode(node: MeteoriteNode)
97 | }
98 |
99 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/security/AdminLoginService.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.api.security
18 |
19 | import javax.security.auth.login.LoginContext
20 |
21 | /**
22 | * Admin Api Interface for user management.
23 | */
24 | trait AdminLoginService {
25 | def login(username: String, password: String): Boolean
26 |
27 | def logout(username: String): Boolean
28 |
29 | def getUsername: String
30 |
31 | def getRoles: List[String]
32 |
33 | /**
34 | * Set the JaaS realm.
35 | *
36 | * @param realm The JAAS Realm
37 | */
38 | def setRealm(realm: String)
39 |
40 | def setLoginContext(loginContext: LoginContext)
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/security/IMeteoriteUser.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.api.security
18 |
19 | /**
20 | * Meteorite User API Object
21 | */
22 | trait IMeteoriteUser {
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/security/IUserManagement.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.api.security
18 |
19 | import bi.meteorite.core.api.objects.MeteoriteUser
20 | import bi.meteorite.core.api.security.exceptions.MeteoriteSecurityException
21 |
22 | /**
23 | * User Management Interface.
24 | */
25 | trait IUserManagement {
26 | @throws(classOf[MeteoriteSecurityException])
27 | def addUser(u: MeteoriteUser): MeteoriteUser
28 |
29 | @throws(classOf[MeteoriteSecurityException])
30 | def deleteUser(u: MeteoriteUser): Boolean
31 |
32 | @throws(classOf[MeteoriteSecurityException])
33 | def setUser(u: MeteoriteUser): MeteoriteUser
34 |
35 | @throws(classOf[MeteoriteSecurityException])
36 | def getUser(id: Int): MeteoriteUser
37 |
38 | @throws(classOf[MeteoriteSecurityException])
39 | def getRoles(u: MeteoriteUser): Array[String]
40 |
41 | @throws(classOf[MeteoriteSecurityException])
42 | def addRole(u: MeteoriteUser)
43 |
44 | @throws(classOf[MeteoriteSecurityException])
45 | def removeRole(u: MeteoriteUser)
46 |
47 | @throws(classOf[MeteoriteSecurityException])
48 | def removeUser(username: String)
49 |
50 | @throws(classOf[MeteoriteSecurityException])
51 | def updateUser(u: MeteoriteUser): MeteoriteUser
52 |
53 | @throws(classOf[MeteoriteSecurityException])
54 | def isAdmin: Boolean
55 |
56 | @throws(classOf[MeteoriteSecurityException])
57 | def getAdminRoles: List[String]
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/security/IUserManagementProvider.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.api.security
18 |
19 | import bi.meteorite.core.api.objects.{UserList, MeteoriteUser}
20 | import bi.meteorite.core.api.security.exceptions.MeteoriteSecurityException
21 | import org.apache.karaf.jaas.config.JaasRealm
22 | import org.apache.karaf.jaas.modules.BackingEngineService
23 |
24 | /**
25 | * User Management Provider.
26 | * API for the main user managaement interface for Meteorite Core.
27 | */
28 | trait IUserManagementProvider {
29 | /**
30 | * Add a new user to the platform.
31 | *
32 | * @param u MeteoriteUser
33 | * @throws MeteoriteSecurityException Throws Meteorite Security Exception on error
34 | */
35 | @throws(classOf[MeteoriteSecurityException])
36 | def addUser(u: MeteoriteUser)
37 |
38 | /**
39 | * Delete a user from the platform.
40 | *
41 | * @param u MeteoriteUser
42 | * @throws MeteoriteSecurityException Throws Meteorite Security Exception on error
43 | */
44 | @throws(classOf[MeteoriteSecurityException])
45 | def deleteUser(u: MeteoriteUser)
46 |
47 | /**
48 | * Delete a user from the platform.
49 | *
50 | * @param u Id
51 | * @throws MeteoriteSecurityException Throws Meteorite Security Exception on error
52 | */
53 | @throws(classOf[MeteoriteSecurityException])
54 | def deleteUser(u: Long)
55 |
56 | /**
57 | * Get a list of users on the platform.
58 | *
59 | * @return a list of usernames.
60 | * @throws MeteoriteSecurityException Throws Meteorite Security Exception on error
61 | */
62 | @throws(classOf[MeteoriteSecurityException])
63 | def getUsers: List[UserList]
64 |
65 | /**
66 | * Get a list of user ids
67 | * @throws MeteoriteSecurityException Throws Meteorite Security Exception on error
68 | * @return a list of user ids
69 | */
70 | @throws(classOf[MeteoriteSecurityException])
71 | def getUsersId: List[Long]
72 |
73 | /**
74 | * Get a list of roles applied to a user.
75 | *
76 | * @param u username
77 | * @return a list of roles.
78 | * @throws MeteoriteSecurityException Throws Meteorite Security Exception on error
79 | */
80 | @throws(classOf[MeteoriteSecurityException])
81 | def getRoles(u: String): List[String]
82 |
83 | /**
84 | * Add a role to a user.
85 | *
86 | * @param u username
87 | * @param r role name
88 | * @throws MeteoriteSecurityException Throws Meteorite Security Exception on error
89 | */
90 | @throws(classOf[MeteoriteSecurityException])
91 | def addRole(u: String, r: String)
92 |
93 | /**
94 | * Remove role from a user
95 | *
96 | * @param u username
97 | * @param r role
98 | * @throws MeteoriteSecurityException Throws Meteorite Security Exception on error
99 | */
100 | @throws(classOf[MeteoriteSecurityException])
101 | def removeRole(u: String, r: String)
102 |
103 | /**
104 | * Update a user on the platform.
105 | *
106 | * @param u user object
107 | * @return a updated user object
108 | * @throws MeteoriteSecurityException Throws Meteorite Security Exception on error
109 | */
110 | @throws(classOf[MeteoriteSecurityException])
111 | def updateUser(u: MeteoriteUser): MeteoriteUser
112 |
113 | /**
114 | * Discover is the user is an administrator or not.
115 | *
116 | * @param u username
117 | * @return true if the user is admin.
118 | * @throws MeteoriteSecurityException Throws Meteorite Security Exception on error
119 | */
120 | @throws(classOf[MeteoriteSecurityException])
121 | def isAdmin(u: String): Boolean
122 |
123 | /**
124 | * Get a list of roles that define an administrator.
125 | *
126 | * @return a list of administrative roles
127 | * @throws MeteoriteSecurityException Throws Meteorite Security Exception on error
128 | */
129 | @throws(classOf[MeteoriteSecurityException])
130 | def getAdminRoles: List[String]
131 |
132 | /**
133 | * Get a single user.
134 | *
135 | * @return a Meteorite User.
136 | * @throws MeteoriteSecurityException Throws Meteorite Security Exception on error
137 | */
138 | @throws(classOf[MeteoriteSecurityException])
139 | def getUser(id: Long): MeteoriteUser
140 |
141 | /**
142 | * Set the backing service engine that drives the security.
143 | *
144 | * @param backingEngineService the backing engine service.
145 | */
146 | def setBackingEngineService(backingEngineService: BackingEngineService)
147 |
148 | /**
149 | * Set the JaaS realm.
150 | *
151 | * @param realm the JAAS Realm
152 | */
153 | def setRealm(realm: JaasRealm)
154 | }
155 |
156 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/security/exceptions/MeteoriteSecurityException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.api.security.exceptions
18 |
19 | /**
20 | * Meteorite Security Exception.
21 | * @param message The error message
22 | */
23 | class MeteoriteSecurityException(message: String = null) extends Exception(message)
24 |
25 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/security/exceptions/TokenProviderException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.api.security.exceptions
18 |
19 | /**
20 | * TokenProviderException for authentication.
21 | * @param message
22 | */
23 | class TokenProviderException(message: String = null) extends Exception(message)
24 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/security/rest/UserAuthentication.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.api.security.rest
18 |
19 | import bi.meteorite.core.api.security.exceptions.TokenProviderException
20 | import javax.ws.rs.POST
21 | import javax.ws.rs.Path
22 | import javax.ws.rs.core.Response
23 |
24 | import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing
25 |
26 | /**
27 | * RESTful interface for authentication.
28 | */
29 | @CrossOriginResourceSharing(allowAllOrigins = true)
30 | @Path("/auth/login") trait UserAuthentication {
31 | /**
32 | * Logout from the Meteorite core.
33 | *
34 | * @param username logout username.
35 | * @return a HTTP response indicating the logout success.
36 | * @throws TokenProviderException
37 | */
38 | @POST
39 | @throws(classOf[TokenProviderException])
40 | def logout(username: String): Response
41 | }
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/security/rest/UserService.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.api.security.rest
18 |
19 | import bi.meteorite.core.api.objects.MeteoriteUser
20 | import bi.meteorite.core.api.security.exceptions.MeteoriteSecurityException
21 | import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing
22 |
23 | //import com.qmino.miredot.annotations.ReturnType
24 | import javax.annotation.security.RolesAllowed
25 | import javax.ws.rs.Consumes
26 | import javax.ws.rs.DELETE
27 | import javax.ws.rs.GET
28 | import javax.ws.rs.POST
29 | import javax.ws.rs.PUT
30 | import javax.ws.rs.Path
31 | import javax.ws.rs.PathParam
32 | import javax.ws.rs.Produces
33 | import javax.ws.rs.core.Response
34 |
35 | /**
36 | * User creation and manipulation for administrators of Meteorite core.
37 | */
38 | @CrossOriginResourceSharing(allowAllOrigins = true,allowCredentials = true)
39 | @Path("/") trait UserService {
40 | /**
41 | * Add a user to Meteorite core.
42 | *
43 | * @param u The Meteorite User object
44 | * @return an HTTP response.
45 | * @throws MeteoriteSecurityException
46 | */
47 | @POST
48 | @Produces(Array("application/json"))
49 | @Consumes(Array("application/json"))
50 | // @ReturnType("bi.meteorite.core.api.objects.MeteoriteUser")
51 | @Path("/user")
52 | @throws(classOf[MeteoriteSecurityException])
53 | def addUser(u: MeteoriteUser): Response
54 |
55 | /**
56 | * Update a user in Meteorite core.
57 | *
58 | * @param u The Meteorite User object.
59 | * @return an HTTP response.
60 | * @throws MeteoriteSecurityException
61 | */
62 | @PUT
63 | @Produces(Array("application/json"))
64 | @Consumes(Array("application/json"))
65 | @Path("/user")
66 | //@ReturnType("bi.meteorite.core.api.objects.MeteoriteUser")
67 | @throws(classOf[MeteoriteSecurityException])
68 | def modifyUser(u: MeteoriteUser): Response
69 |
70 | /**
71 | * Remove a user from Meteorite core.
72 | *
73 | * @param u The Meteorite User object.
74 | * @return An HTTP response code.
75 | * @throws MeteoriteSecurityException
76 | */
77 | @DELETE
78 | @Produces(Array("application/json"))
79 | @Consumes(Array("application/json"))
80 | @Path("/user")
81 | //@ReturnType("bi.meteorite.core.api.objects.MeteoriteUser")
82 | @throws(classOf[MeteoriteSecurityException])
83 | def deleteUser(u: MeteoriteUser): Response
84 |
85 | /**
86 | * Remove a user from Meteorite core.
87 | *
88 | * @param id The User ID.
89 | * @return An HTTP response code.
90 | * @throws MeteoriteSecurityException
91 | */
92 | @DELETE
93 | @Produces(Array("application/json"))
94 | @Consumes(Array("application/json"))
95 | @Path("/user/{id}")
96 | //@ReturnType("bi.meteorite.core.api.objects.MeteoriteUser")
97 | @throws(classOf[MeteoriteSecurityException])
98 | def deleteUser(@PathParam("id") id: Int): Response
99 |
100 | /**
101 | * Add user to a group.
102 | *
103 | * @param group The group
104 | * @return An HTTP response.
105 | * @throws MeteoriteSecurityException
106 | */
107 | @POST
108 | @Produces(Array("application/json"))
109 | @Consumes(Array("application/json"))
110 | @Path("/user/lookup/{id}/group/{gid}")
111 | @throws(classOf[MeteoriteSecurityException])
112 | def addRole(@PathParam("id") id: String, @PathParam("gid") group: Int): Response
113 |
114 | /**
115 | * Add user to a group by group name.
116 | *
117 | * @param group The group
118 | * @return An HTTP response.
119 | * @throws MeteoriteSecurityException
120 | */
121 | @POST
122 | @Produces(Array("application/json"))
123 | @Consumes(Array("application/json"))
124 | @Path("/user/lookup/{id}/group/{group}")
125 | @throws(classOf[MeteoriteSecurityException])
126 | def addRole(@PathParam("id") id: String, @PathParam("group") group: String): Response
127 |
128 | /**
129 | * Get a list of existing users.
130 | *
131 | * @return a list of existing users.
132 | * @throws MeteoriteSecurityException
133 | */
134 | @GET
135 | @Produces(Array("application/json"))
136 | @Path("/user")
137 | //@ReturnType("java.util.List")
138 | @RolesAllowed(Array("admin"))
139 | @throws(classOf[MeteoriteSecurityException])
140 | def getExistingUsers: Response
141 |
142 | /**
143 | * Get a user by id.
144 | *
145 | * @param id the user id.
146 | * @return an HTTP response code.
147 | * @throws MeteoriteSecurityException
148 | */
149 | @GET
150 | @Produces(Array("application/json"))
151 | @Path("/user/lookup/{id}")
152 | //@ReturnType("bi.meteorite.core.api.objects.MeteoriteUser")
153 | @throws(classOf[MeteoriteSecurityException])
154 | def getUser(@PathParam("id") id: Int): Response
155 |
156 | /**
157 | * Discover who is logged in.
158 | *
159 | * @return an HTTP response code.
160 | * @throws MeteoriteSecurityException
161 | */
162 | @GET
163 | @Produces(Array("application/json"))
164 | @Path("/user/whoami")
165 | //@ReturnType("bi.meteorite.core.api.objects.MeteoriteUser")
166 | @throws(classOf[MeteoriteSecurityException])
167 | def whoami: Response
168 | }
169 |
170 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/security/tokenprovider/IToken.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.api.security.tokenprovider
18 |
19 |
20 | /**
21 | * An authentication token.
22 | */
23 | trait IToken {
24 | def getToken: String
25 |
26 | def setToken(token: String)
27 |
28 | def getTokenSecret: String
29 |
30 | def setTokenSecret(tokenSecret: String)
31 |
32 | def getTimestamp: Long
33 |
34 | def setTimestamp(timestamp: Long)
35 |
36 | def getProperties: Map[String, String]
37 |
38 | def getProperty(key: String): String
39 |
40 | def setProperties(properties: Map[String, String])
41 |
42 | def setProperty(key: String, value: String)
43 |
44 | def isExpired(validityDuration: Long): Boolean
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/security/tokenprovider/InvalidTokenException.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.api.security.tokenprovider
18 |
19 | /**
20 | * Invalid Token Exception for authentication purposes.
21 | * @param message
22 | */
23 | @SerialVersionUID(783720889456143935L)
24 | class InvalidTokenException(message: String = null) extends Exception(message)
25 |
26 |
--------------------------------------------------------------------------------
/api/src/main/scala/bi/meteorite/core/api/security/tokenprovider/TokenProvider.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.api.security.tokenprovider
17 |
18 | import bi.meteorite.core.api.security.exceptions.TokenProviderException
19 | import javax.servlet.http.HttpServletRequest
20 |
21 | import scala.collection.immutable.TreeMap
22 |
23 | trait TokenProvider {
24 | /**
25 | * Generates a new token for the specified set of token attributes. First of all a signature is created from the set
26 | * of attributes using a private key, only known by this token provider. The attributes are converted to a single
27 | * String and together with the signature this forms the unencrypted token. Finally, the token is encrypted using aAES
28 | * encryption method, again using a private key only known by this token provider. This encrypted token is returned.
29 | * Note that to this list of attributes always a nonce and a timestamp are added. Therefore attributes with names
30 | * NONCE or TIMESTAMP are preserved and should not be used. A TokenProviderException is thrown in case the map of
31 | * attributes already contains these attributes.
32 | *
33 | * @param attributes The attributes to create the token for. May be empty or null, in which case the token is
34 | * generated from only a nonce and a timestamp.
35 | * @return The generated encrypted token
36 | * @throws TokenProviderException In case an unexpected error occurred during token generation.
37 | */
38 | @throws(classOf[TokenProviderException])
39 | def generateToken(attributes: TreeMap[String, String]): String
40 |
41 | /**
42 | * Verifies if the token is valid. If the token is valid, a map of attributes is returned which are included in the
43 | * token. This is the same list as provided when the token was generated, but with additional nonce and timestamp
44 | * attributes. If the token is invalid, a InvalidTokenException is thrown.
45 | *
46 | * @param encryptedToken The encrypted token to verify
47 | * @return List of original attributes, plus nonce and timestamp attributes.
48 | * @throws TokenProviderException In case an unexpected error occurred during token generation.
49 | */
50 | @throws(classOf[TokenProviderException])
51 | def verifyToken(encryptedToken: String): TreeMap[String, String]
52 |
53 | /**
54 | * Invalidates the specified token. A token that has been invalidated cannot be used anymore.
55 | *
56 | * @param encryptedToken the token to invalidate.
57 | */
58 | def invalidateToken(encryptedToken: String)
59 |
60 | def getTokenFromRequest(request: HttpServletRequest): String
61 | }
62 |
63 |
64 | /**
65 | * The Token Provider.
66 | */
67 | object TokenProvider {
68 | /**
69 | * The PID of the configuration of this service.
70 | */
71 | val PID: String = "org.amdatu.security.tokenprovider"
72 | /**
73 | * Name of the cookie that stores an Amdatu token.
74 | */
75 | val TOKEN_COOKIE_NAME: String = "saiku_token"
76 | /**
77 | * Name under which the nonce parameter is stored.
78 | */
79 | val NONCE: String = "token_nonce"
80 | /**
81 | * Name under which the timestamp parameter is stored.
82 | */
83 | val TIMESTAMP: String = "token_timestamp"
84 | /**
85 | * Name under which the tenant parameter is stored.
86 | */
87 | val TENANTID: String = "tenantid"
88 | /**
89 | * Name under which a username parameter can be stored (this is optional).
90 | */
91 | val USERNAME: String = "token_username"
92 | /**
93 | * Comma delimited role list (this is optional).
94 | */
95 | val ROLES: String = "token_rolelist"
96 | }
97 |
--------------------------------------------------------------------------------
/features/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | bi.meteorite
8 | core
9 | 1.0-SNAPSHOT
10 |
11 |
12 | meteorite-core-features
13 | 1.0-SNAPSHOT
14 | feature
15 | Meteorite Core Features
16 | The Apache Karaf features build for Meteorite Core
17 |
18 | ../
19 |
20 |
21 |
22 | bi.meteorite
23 | meteorite-core-api
24 | ${version}
25 |
26 |
27 | javax.annotation
28 | jsr250-api
29 |
30 |
31 |
32 |
33 | bi.meteorite
34 | meteorite-core-model-scala
35 | ${version}
36 |
37 |
38 | bi.meteorite
39 | meteorite-core-persistence
40 | ${version}
41 |
42 |
43 | bi.meteorite
44 | meteorite-core-security-provider-scala
45 | ${version}
46 |
47 |
48 | bi.meteorite
49 | meteorite-core-security-scala
50 | ${version}
51 |
52 |
53 | bi.meteorite
54 | ui
55 | ${version}
56 |
57 |
58 | bi.meteorite
59 | ui-shared
60 | ${version}
61 |
62 |
63 |
64 |
65 |
66 |
67 | org.apache.karaf.tooling
68 | karaf-maven-plugin
69 | 4.0.0
70 | true
71 |
72 |
73 |
74 |
75 |
76 | org.apache.karaf.tooling
77 | karaf-maven-plugin
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/features/src/main/feature/feature.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Enable Hibernate 4.3.x as persistence engine.
7 | http
8 | persistence-api
9 | mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5
10 | mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.ant/1.8.2_2
11 | mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5
12 | mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.serp/1.14.1_1
13 | mvn:com.fasterxml/classmate/1.1.0
14 | mvn:org.javassist/javassist/3.18.1-GA
15 | mvn:org.jboss.spec.javax.security.jacc/jboss-jacc-api_1.4_spec/1.0.2.Final
16 | mvn:org.jboss/jandex/1.2.2.Final
17 | mvn:org.jboss.logging/jboss-logging/3.1.4.GA
18 | mvn:org.hibernate.common/hibernate-commons-annotations/4.0.4.Final
19 | mvn:org.hibernate/hibernate-core/4.3.5.Final
20 | mvn:org.hibernate/hibernate-entitymanager/4.3.5.Final
21 | mvn:org.hibernate/hibernate-osgi/4.3.5.Final
22 |
23 |
24 |
--------------------------------------------------------------------------------
/karaf/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | bi.meteorite
8 | core
9 | 1.0-SNAPSHOT
10 |
11 |
12 | meteorite-engine
13 | 1.0-SNAPSHOT
14 | karaf-assembly
15 |
16 | Meteorite Core Karaf Engine
17 | The main executable of the Meteorite Core build.
18 |
19 | ../
20 |
21 |
22 |
23 | bi.meteorite
24 | meteorite-core-features
25 | ${version}
26 | features
27 | xml
28 | runtime
29 |
30 |
31 | org.apache.cxf.karaf
32 | apache-cxf
33 | features
34 | xml
35 | runtime
36 |
37 |
38 | org.apache.karaf.cellar
39 | apache-karaf-cellar
40 | features
41 | xml
42 | runtime
43 |
44 |
45 | org.apache.karaf.features
46 | enterprise
47 | features
48 | xml
49 | runtime
50 |
51 |
52 | org.apache.karaf.features
53 | framework
54 | kar
55 |
56 |
57 | org.apache.karaf.features
58 | spring
59 | features
60 | xml
61 | runtime
62 |
63 |
64 | org.apache.karaf.features
65 | standard
66 | features
67 | xml
68 | runtime
69 |
70 |
71 | org.ops4j.pax.jdbc
72 | pax-jdbc-features
73 | features
74 | xml
75 | runtime
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | false
85 | src/main/resources
86 |
87 | **/*
88 |
89 |
90 |
91 | true
92 | src/main/filtered-resources
93 |
94 | **/*
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 | org.apache.maven.plugins
103 | maven-resources-plugin
104 | 2.6
105 |
106 |
107 | process-resources
108 |
109 | resources
110 |
111 |
112 |
113 |
114 |
115 | org.apache.karaf.tooling
116 | karaf-maven-plugin
117 | ${karaf.version}
118 | true
119 |
120 |
121 |
122 | jaas
123 | shell
124 | ssh
125 | management
126 | bundle
127 | config
128 | deployer
129 | diagnostic
130 | instance
131 | kar
132 | log
133 | package
134 | service
135 | system
136 | feature
137 | wrap
138 | spring
139 | spring-web
140 | aries-blueprint
141 | http-whiteboard
142 | cxf
143 | cellar
144 | custom-hibernate
145 | pax-cdi
146 | transaction
147 | jndi
148 | jpa
149 | jdbc
150 | pax-jdbc
151 | pax-jdbc-h2
152 | pax-jdbc-derby
153 | pax-jdbc-config
154 | pax-jdbc-pool-dbcp2
155 |
156 |
157 |
159 | meteorite-core-features
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
--------------------------------------------------------------------------------
/karaf/src/main/karaf/assembly-property-edits.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | system.properties
6 | put
7 | javax.ws.rs.ext.RuntimeDelegate
8 | org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl
9 |
10 |
11 | config.properties
12 | put
13 | karaf.framework
14 | equinox
15 |
16 |
17 |
--------------------------------------------------------------------------------
/karaf/src/main/resources/etc/org.ops4j.datasource-eventslist.cfg:
--------------------------------------------------------------------------------
1 | osgi.jdbc.driver.name=derby
2 | url=jdbc:derby:memory:system;create=true
3 | dataSourceName=systemdb
--------------------------------------------------------------------------------
/karaf/src/main/resources/etc/org.ops4j.pax.url.mvn.cfg:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | #
3 | # Licensed to the Apache Software Foundation (ASF) under one or more
4 | # contributor license agreements. See the NOTICE file distributed with
5 | # this work for additional information regarding copyright ownership.
6 | # The ASF licenses this file to You under the Apache License, Version 2.0
7 | # (the "License"); you may not use this file except in compliance with
8 | # the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | ################################################################################
19 |
20 | #
21 | # If set to true, the following property will not allow any certificate to be used
22 | # when accessing Maven repositories through SSL
23 | #
24 | #org.ops4j.pax.url.mvn.certificateCheck=
25 |
26 | #
27 | # Path to the local Maven settings file.
28 | # The repositories defined in this file will be automatically added to the list
29 | # of default repositories if the 'org.ops4j.pax.url.mvn.repositories' property
30 | # below is not set.
31 | # The following locations are checked for the existence of the settings.xml file
32 | # * 1. looks for the specified url
33 | # * 2. if not found looks for ${user.home}/.m2/settings.xml
34 | # * 3. if not found looks for ${maven.home}/conf/settings.xml
35 | # * 4. if not found looks for ${M2_HOME}/conf/settings.xml
36 | #
37 | #org.ops4j.pax.url.mvn.settings=
38 |
39 | #
40 | # Path to the local Maven repository which is used to avoid downloading
41 | # artifacts when they already exist locally.
42 | # The value of this property will be extracted from the settings.xml file
43 | # above, or defaulted to:
44 | # System.getProperty( "user.home" ) + "/.m2/repository"
45 | #
46 | #org.ops4j.pax.url.mvn.localRepository=
47 |
48 | #
49 | # Default this to false. It's just weird to use undocumented repos
50 | #
51 | org.ops4j.pax.url.mvn.useFallbackRepositories=false
52 |
53 | #
54 | # Uncomment if you don't wanna use the proxy settings
55 | # from the Maven conf/settings.xml file
56 | #
57 | # org.ops4j.pax.url.mvn.proxySupport=false
58 |
59 | #
60 | # Comma separated list of repositories scanned when resolving an artifact.
61 | # Those repositories will be checked before iterating through the
62 | # below list of repositories and even before the local repository
63 | # A repository url can be appended with zero or more of the following flags:
64 | # @snapshots : the repository contains snaphots
65 | # @noreleases : the repository does not contain any released artifacts
66 | #
67 | # The following property value will add the system folder as a repo.
68 | #
69 | org.ops4j.pax.url.mvn.defaultRepositories=\
70 | file:${karaf.home}/${karaf.default.repository}@id=system.repository@snapshots, \
71 | file:${karaf.data}/kar@id=kar.repository@multi@snapshots, \
72 | file:${karaf.base}/${karaf.default.repository}@id=child.system.repository@snapshots
73 |
74 | # Use the default local repo (e.g.~/.m2/repository) as a "remote" repo
75 | #org.ops4j.pax.url.mvn.defaultLocalRepoAsRemote=false
76 |
77 | #
78 | # Comma separated list of repositories scanned when resolving an artifact.
79 | # The default list includes the following repositories:
80 | # http://repo1.maven.org/maven2@id=central
81 | # http://repository.springsource.com/maven/bundles/release@id=spring.ebr
82 | # http://repository.springsource.com/maven/bundles/external@id=spring.ebr.external
83 | # http://zodiac.springsource.com/maven/bundles/release@id=gemini
84 | # http://repository.apache.org/content/groups/snapshots-group@id=apache@snapshots@noreleases
85 | # https://oss.sonatype.org/content/repositories/snapshots@id=sonatype.snapshots.deploy@snapshots@noreleases
86 | # https://oss.sonatype.org/content/repositories/ops4j-snapshots@id=ops4j.sonatype.snapshots.deploy@snapshots@noreleases
87 | # To add repositories to the default ones, prepend '+' to the list of repositories
88 | # to add.
89 | # A repository url can be appended with zero or more of the following flags:
90 | # @snapshots : the repository contains snapshots
91 | # @noreleases : the repository does not contain any released artifacts
92 | # @id=repository.id : the id for the repository, just like in the settings.xml this is optional but recommended
93 | #
94 | org.ops4j.pax.url.mvn.repositories= \
95 | http://repo1.maven.org/maven2@id=central, \
96 | http://repository.springsource.com/maven/bundles/release@id=spring.ebr.release, \
97 | http://repository.springsource.com/maven/bundles/external@id=spring.ebr.external, \
98 | http://zodiac.springsource.com/maven/bundles/release@id=gemini, \
99 | http://repository.apache.org/content/groups/snapshots-group@id=apache@snapshots@noreleases, \
100 | https://oss.sonatype.org/content/repositories/snapshots@id=sonatype.snapshots.deploy@snapshots@noreleases, \
101 | https://oss.sonatype.org/content/repositories/ops4j-snapshots@id=ops4j.sonatype.snapshots.deploy@snapshots@noreleases, \
102 | http://repository.springsource.com/maven/bundles/external@id=spring-ebr-repository@snapshots@noreleases, \
103 | http://repo.meteorite.bi/content/repositories/alabs-snapshot-local@id=alabs-snapshot@snapshots@noreleases, \
104 | http://repo.meteorite.bi/content/repositories/alabs-release-local@id=alabs-releases
105 |
106 | org.ops4j.pax.url.mvn.globalUpdatePolicy=always
107 |
--------------------------------------------------------------------------------
/karaf/src/main/resources/etc/system.properties:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | #
3 | # Licensed to the Apache Software Foundation (ASF) under one or more
4 | # contributor license agreements. See the NOTICE file distributed with
5 | # this work for additional information regarding copyright ownership.
6 | # The ASF licenses this file to You under the Apache License, Version 2.0
7 | # (the "License"); you may not use this file except in compliance with
8 | # the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | ################################################################################
19 |
20 | #
21 | # The properties defined in this file will be made available through system
22 | # properties at the very beginning of the Karaf's boot process.
23 | #
24 |
25 |
26 | # Log level when the pax-logging service is not available
27 | # This level will only be used while the pax-logging service bundle
28 | # is not fully available.
29 | # To change log levels, please refer to the org.ops4j.pax.logging.cfg file
30 | # instead.
31 | org.ops4j.pax.logging.DefaultServiceLog.level = ERROR
32 |
33 | #
34 | # Name of this Karaf instance.
35 | #
36 | karaf.name = root
37 |
38 | #
39 | # Default repository where bundles will be loaded from before using
40 | # other Maven repositories. For the full Maven configuration, see
41 | # the org.ops4j.pax.url.mvn.cfg file.
42 | #
43 | karaf.default.repository = system
44 |
45 | #
46 | # Location of a shell script that will be run when starting a shell
47 | # session. This script can be used to create aliases and define
48 | # additional commands.
49 | #
50 | karaf.shell.init.script = ${karaf.etc}/shell.init.script
51 |
52 | #
53 | # Sets the maximum size of the shell command history. If not set,
54 | # defaults to 500 entries. Setting to 0 will disable history.
55 | #
56 | # karaf.shell.history.maxSize = 0
57 |
58 | #
59 | # Deletes the entire karaf.data directory at every start
60 | #
61 | karaf.clean.all = false
62 |
63 | #
64 | # Deletes the karaf.data/cache directory at every start
65 | #
66 | karaf.clean.cache = false
67 |
68 | #
69 | # User name for the Karaf local console
70 | #
71 | karaf.local.user = karaf
72 |
73 | #
74 | # Roles to use when for the default user in the local Karaf console.
75 | #
76 | # The syntax is the following:
77 | # [classname:]principal
78 | # where classname is the class name of the principal object
79 | # (defaults to org.apache.karaf.jaas.modules.RolePrincipal)
80 | # and principal is the name of the principal of that class
81 | # (defaults to instance).
82 | #
83 | karaf.local.roles = admin,manager,viewer,systembundles
84 |
85 | #
86 | # Set this empty property to avoid errors when validating xml documents.
87 | #
88 | xml.catalog.files =
89 |
90 | #
91 | # Suppress the bell in the console when hitting backspace too many times
92 | # for example
93 | #
94 | jline.nobell = true
95 |
96 | #
97 | # ServiceMix specs options
98 | #
99 | org.apache.servicemix.specs.debug = false
100 | org.apache.servicemix.specs.timeout = 0
101 |
102 | #
103 | # Settings for the OSGi 4.3 Weaving
104 | # By default, we will not weave any classes. Change this setting to include classes
105 | # that you application needs to have woven.
106 | #
107 | org.apache.aries.proxy.weaving.enabled = none
108 | # Classes not to weave - Aries default + Xerces which is known to have issues.
109 | org.apache.aries.proxy.weaving.disabled = org.objectweb.asm.*,org.slf4j.*,org.apache.log4j.*,javax.*,org.apache.xerces.*
110 |
111 | #
112 | # By default, only Karaf shell commands are secured, but additional services can be
113 | # secured by expanding this filter
114 | #
115 | karaf.secured.services = (&(osgi.command.scope=*)(osgi.command.function=*))
116 |
117 | #
118 | # By default, if there's no ACL policy for a certain karaf command, this command is allowed to access
119 | # without the RBAC. We can change this behavior by enable the following property, which means
120 | # if a karaf command has no corresponding ACL then access it must have one of the karaf.secured.command.compulsory.roles
121 | #
122 | #karaf.secured.command.compulsory.roles=admin
123 |
124 | #
125 | # Security properties
126 | #
127 | # To enable OSGi security, uncomment the properties below,
128 | # install the framework-security feature and restart.
129 | #
130 | #java.security.policy=${karaf.etc}/all.policy
131 | #org.osgi.framework.security=osgi
132 | #org.osgi.framework.trust.repositories=${karaf.etc}/trustStore.ks
133 |
134 | #
135 | # HA/Lock configuration
136 | #
137 | # Karaf uses a lock mechanism to know which instance is the master (HA)
138 | # The lock can be on the filesystem (default) or on a database.
139 | #
140 | # See http://karaf.apache.org/manual/latest/users-guide/failover.html for details.
141 | #
142 | # Even using a single instance, Karaf creates the lock file
143 | # You can specify the location of the lock file using the
144 | # karaf.lock.dir=/path/to/the/directory/containing/the/lock
145 | #
146 |
147 | javax.ws.rs.ext.RuntimeDelegate=org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl
--------------------------------------------------------------------------------
/meteorite-core-itests/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | bi.meteorite
6 | core
7 | 1.0-SNAPSHOT
8 |
9 |
10 | meteorite-core-itests
11 | 1.0-SNAPSHOT
12 | jar
13 |
14 | Meteorite Core Itests
15 | Meteorite Core Integration Tests
16 |
17 | UTF-8
18 | ../
19 |
20 |
21 |
22 | bi.meteorite
23 | meteorite-core-api
24 | ${version}
25 |
26 |
27 | bi.meteorite
28 | meteorite-core-security-provider-scala
29 | ${version}
30 |
31 |
32 | bi.meteorite
33 | meteorite-core-security-scala
34 | ${version}
35 |
36 |
37 | com.fasterxml.jackson.jaxrs
38 | jackson-jaxrs-json-provider
39 | 2.6.2
40 | test
41 |
42 |
43 | com.hazelcast
44 | hazelcast
45 |
46 |
47 | commons-codec
48 | commons-codec
49 | provided
50 |
51 |
52 | javax.inject
53 | javax.inject
54 | test
55 |
56 |
57 | javax.servlet
58 | servlet-api
59 | provided
60 |
61 |
62 |
63 | javax.ws.rs
64 | javax.ws.rs-api
65 |
66 |
67 | junit
68 | junit
69 | test
70 |
71 |
72 | org.apache.cxf
73 | cxf-rt-rs-client
74 | test
75 |
76 |
77 | org.apache.cxf
78 | cxf-rt-rs-extension-providers
79 | 3.1.2
80 |
81 |
82 | org.apache.karaf.features
83 | org.apache.karaf.features.core
84 |
85 |
86 | org.apache.karaf.features
87 | standard
88 | features
89 | xml
90 | test
91 |
92 |
93 | org.apache.karaf.shell
94 | org.apache.karaf.shell.core
95 | test
96 |
97 |
98 | org.ops4j.pax.exam
99 | pax-exam
100 | test
101 |
102 |
103 | org.ops4j.pax.exam
104 | pax-exam-container-karaf
105 | test
106 |
107 |
108 |
109 | org.ops4j.pax.exam
110 | pax-exam-junit4
111 | test
112 |
113 |
114 |
115 | org.ops4j.pax.exam
116 | pax-exam-link-assembly
117 | test
118 |
119 |
120 | org.ops4j.pax.exam
121 | pax-exam-link-mvn
122 | test
123 |
124 |
125 | org.osgi
126 | org.osgi.core
127 |
128 |
129 | org.osgi
130 | org.osgi.enterprise
131 | test
132 |
133 |
134 | org.scala-lang
135 | scala-library
136 | 2.11.7
137 |
138 |
139 | org.slf4j
140 | slf4j-api
141 |
142 |
143 | org.slf4j
144 | slf4j-simple
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 | com.atlassian.maven.plugins
153 | maven-clover2-plugin
154 |
155 |
156 | none
157 |
158 |
159 |
160 |
161 |
162 | http://maven.apache.org
163 |
164 |
--------------------------------------------------------------------------------
/meteorite-core-itests/src/test/java/bi/meteorite/core/security/TestSecurity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security;
18 |
19 | import bi.meteorite.core.api.persistence.UserService;
20 | import bi.meteorite.core.api.security.exceptions.MeteoriteSecurityException;
21 | import bi.meteorite.core.api.security.exceptions.TokenProviderException;
22 | import bi.meteorite.core.api.security.rest.UserAuthentication;
23 | import bi.meteorite.util.ITestBootstrap;
24 |
25 | import org.apache.karaf.features.FeaturesService;
26 |
27 | import org.junit.Test;
28 | import org.junit.runner.RunWith;
29 | import org.ops4j.pax.exam.junit.PaxExam;
30 | import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
31 | import org.ops4j.pax.exam.spi.reactors.PerMethod;
32 | import org.ops4j.pax.exam.util.Filter;
33 | import org.osgi.framework.BundleContext;
34 | import org.osgi.service.cm.ConfigurationAdmin;
35 | import org.osgi.service.jdbc.DataSourceFactory;
36 | import org.osgi.util.tracker.ServiceTracker;
37 |
38 | import java.sql.SQLException;
39 |
40 | import javax.inject.Inject;
41 | import javax.sql.DataSource;
42 | import javax.ws.rs.core.MediaType;
43 | import javax.ws.rs.core.Response;
44 |
45 | import static org.hamcrest.CoreMatchers.containsString;
46 | import static org.hamcrest.CoreMatchers.is;
47 | import static org.hamcrest.MatcherAssert.assertThat;
48 | import static org.junit.Assert.assertNotNull;
49 |
50 | /**
51 | * Tests for the authentication mechanism for Meteorite Core.
52 | */
53 | @RunWith(PaxExam.class)
54 | @ExamReactorStrategy(PerMethod.class)
55 | public class TestSecurity extends ITestBootstrap {
56 |
57 | @Inject
58 | protected FeaturesService featuresService;
59 |
60 | @Inject
61 | private ConfigurationAdmin caService;
62 |
63 | @Filter(timeout = 30000L)
64 | @Inject
65 | private UserAuthentication authenticationService;
66 |
67 | @Filter(timeout = 30000L)
68 | @Inject
69 | private UserService userService;
70 |
71 | @Inject
72 | @Filter(value = "(osgi.jdbc.driver.class=org.h2.Driver)", timeout = 30000L)
73 | private DataSourceFactory dsf;
74 |
75 | @Inject
76 | BundleContext context;
77 |
78 | /**
79 | * Test that a user can login
80 | *
81 | * @throws Exception
82 | */
83 | @Test
84 | public void testLoginService() throws Exception {
85 | assertNotNull(caService);
86 | assertNotNull(authenticationService);
87 | assertNotNull(dsf);
88 | ServiceTracker tracker = new ServiceTracker(
89 | context, DataSource.class, null);
90 | tracker.open();
91 | DataSource dataSource = (DataSource) tracker.waitForService(10000);
92 |
93 | Response response = get("http://localhost:8181/cxf/rest/core/user", MediaType.APPLICATION_JSON);
94 |
95 | assertThat(response.getStatusInfo().getFamily(), is(Response.Status.Family.CLIENT_ERROR));
96 | //assertThat(response.readEntity(String.class), containsString("Username can not be null"));
97 |
98 | response = get("http://localhost:8181/cxf/rest/core/user", "admin", "admin", MediaType.APPLICATION_JSON);
99 |
100 | assertThat(response.getStatusInfo().getFamily(), is(Response.Status.Family.SUCCESSFUL));
101 |
102 | }
103 |
104 | /**
105 | * Test that an admin user can login and get a response from a admin only, and non admin endpoint.
106 | *
107 | * @throws TokenProviderException
108 | */
109 | @Test
110 | public void testRoleRestrictedEndpoints() throws TokenProviderException, SQLException, InterruptedException {
111 | assertNotNull(caService);
112 | assertNotNull(authenticationService);
113 | assertNotNull(dsf);
114 | ServiceTracker tracker = new ServiceTracker(
115 | context, DataSource.class, null);
116 | tracker.open();
117 | DataSource dataSource = (DataSource) tracker.waitForService(10000);
118 | Response response = get("http://localhost:8181/cxf/rest/core/user/whoami", "admin", "admin", MediaType
119 | .APPLICATION_JSON);
120 |
121 | assertThat(response.getStatusInfo().getFamily(), is(Response.Status.Family.SUCCESSFUL));
122 |
123 | assertThat(response.readEntity(String.class), containsString("test3"));
124 |
125 | response = get("http://localhost:8181/cxf/rest/core/user", "admin", "admin", MediaType.APPLICATION_JSON);
126 |
127 | assertThat(response.getStatusInfo().getFamily(), is(Response.Status.Family.SUCCESSFUL));
128 |
129 | }
130 |
131 | /**
132 | * Test that a non admin user can login but not hit an admin only endpoint.
133 | *
134 | * @throws MeteoriteSecurityException
135 | */
136 | @Test
137 | public void testNonAdminLockDown() throws MeteoriteSecurityException, SQLException, InterruptedException {
138 | assertNotNull(caService);
139 | assertNotNull(authenticationService);
140 | assertNotNull(dsf);
141 | ServiceTracker tracker = new ServiceTracker(
142 | context, DataSource.class, null);
143 | tracker.open();
144 | DataSource dataSource = (DataSource) tracker.waitForService(10000);
145 | Response response = get("http://localhost:8181/cxf/rest/core/user/whoami", "smith", "smith", MediaType
146 | .APPLICATION_JSON);
147 |
148 | assertThat(response.getStatusInfo().getFamily(), is(Response.Status.Family.SUCCESSFUL));
149 |
150 | response = get("http://localhost:8181/cxf/rest/core/user", "smith", "smith", MediaType
151 | .APPLICATION_JSON);
152 |
153 | assertThat(response.getStatusInfo().getFamily(), is(Response.Status.Family.CLIENT_ERROR));
154 | }
155 |
156 |
157 | /**
158 | * Test that an admin and a non admin user login but the non admin user cannot imitate the admin user.
159 | *
160 | * @throws MeteoriteSecurityException
161 | */
162 | @Test
163 | public void testCheckDualLogins() throws MeteoriteSecurityException {
164 | Thread thread1 = new Thread() {
165 | public void run() {
166 | try {
167 | testNonAdminLockDown();
168 | } catch (MeteoriteSecurityException e) {
169 | e.printStackTrace();
170 | } catch (SQLException e) {
171 | e.printStackTrace();
172 | } catch (InterruptedException e) {
173 | e.printStackTrace();
174 | }
175 | }
176 | };
177 |
178 | Thread thread2 = new Thread() {
179 | public void run() {
180 | try {
181 | testRoleRestrictedEndpoints();
182 | } catch (TokenProviderException e) {
183 | e.printStackTrace();
184 | } catch (SQLException e) {
185 | e.printStackTrace();
186 | } catch (InterruptedException e) {
187 | e.printStackTrace();
188 | }
189 | }
190 | };
191 |
192 | thread1.start();
193 | thread2.start();
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/meteorite-core-itests/src/test/java/bi/meteorite/core/security/TestUserAdmin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security;
17 |
18 | import bi.meteorite.core.api.objects.MeteoriteUser;
19 | import bi.meteorite.core.api.persistence.UserService;
20 | import bi.meteorite.core.api.security.rest.UserAuthentication;
21 | import bi.meteorite.core.security.rest.objects.UserObj;
22 | import bi.meteorite.util.ITestBootstrap;
23 |
24 | import org.apache.karaf.features.FeaturesService;
25 |
26 | import org.junit.Ignore;
27 | import org.junit.Test;
28 | import org.junit.runner.RunWith;
29 | import org.ops4j.pax.exam.junit.PaxExam;
30 | import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
31 | import org.ops4j.pax.exam.spi.reactors.PerMethod;
32 | import org.ops4j.pax.exam.util.Filter;
33 | import org.osgi.framework.BundleContext;
34 | import org.osgi.service.cm.ConfigurationAdmin;
35 | import org.osgi.service.jdbc.DataSourceFactory;
36 |
37 | import javax.inject.Inject;
38 | import javax.ws.rs.core.MediaType;
39 | import javax.ws.rs.core.Response;
40 |
41 | import static org.junit.Assert.assertNotNull;
42 |
43 | /**
44 | * Created by bugg on 27/01/16.
45 | */
46 | @RunWith(PaxExam.class)
47 | @ExamReactorStrategy(PerMethod.class)
48 | public class TestUserAdmin extends ITestBootstrap {
49 |
50 | @Inject
51 | protected FeaturesService featuresService;
52 |
53 | @Inject
54 | private ConfigurationAdmin caService;
55 |
56 | @Filter(timeout = 30000L)
57 | @Inject
58 | private UserAuthentication authenticationService;
59 |
60 | @Filter(timeout = 30000L)
61 | @Inject
62 | private UserService userService;
63 |
64 | @Inject
65 | @Filter(value = "(osgi.jdbc.driver.class=org.h2.Driver)", timeout = 30000L)
66 | private DataSourceFactory dsf;
67 |
68 | @Inject
69 | BundleContext context;
70 |
71 | @Test
72 | public void testAddUser() {
73 | MeteoriteUser u = new UserObj();
74 | u.setUsername("testuser");
75 | u.setEmail("testemail@test.com");
76 | u.setPassword("testpassword");
77 |
78 |
79 | Response response = post("http://localhost:8181/cxf/rest/core/user", "admin", "admin", MediaType
80 | .APPLICATION_JSON, u, MeteoriteUser.class);
81 |
82 |
83 | assertNotNull(response.readEntity(String.class));
84 |
85 | System.out.println("here");
86 |
87 | }
88 |
89 | @Ignore
90 | @Test
91 | public void testDeleteUser() {
92 |
93 | }
94 |
95 | @Ignore
96 | @Test
97 | public void testAddRoles() {
98 |
99 | }
100 |
101 | @Ignore
102 | @Test
103 | public void testDeleteRoles() {
104 |
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/meteorite-core-itests/src/test/java/bi/meteorite/core/security/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * Security Package.
19 | */
20 | package bi.meteorite.core.security;
21 |
--------------------------------------------------------------------------------
/meteorite-core-itests/src/test/java/bi/meteorite/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * Root package.
19 | */
20 | package bi.meteorite;
21 |
--------------------------------------------------------------------------------
/meteorite-core-itests/src/test/java/bi/meteorite/util/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * Utility classes.
19 | */
20 | package bi.meteorite.util;
21 |
--------------------------------------------------------------------------------
/meteorite-core-itests/src/test/resources/org.ops4j.datasource-users.cfg:
--------------------------------------------------------------------------------
1 | url=jdbc:h2:mem:users
2 | dataSourceName=userlist
3 | osgi.jdbc.driver.name=H2-pool-xa
4 |
--------------------------------------------------------------------------------
/meteorite-persistence/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | bi.meteorite
6 | core
7 | 1.0-SNAPSHOT
8 |
9 | meteorite-core-persistence
10 | 1.0-SNAPSHOT
11 | bundle
12 | Meteorite Core Persistence Manager
13 | Persist information in hibernate.
14 |
15 | 4.6.0
16 | ../
17 |
18 |
19 |
20 | bi.meteorite
21 | meteorite-core-api
22 | 1.0-SNAPSHOT
23 | provided
24 |
25 |
26 | javax.annotation
27 | jsr250-api
28 |
29 |
30 |
31 |
32 | bi.meteorite
33 | meteorite-core-model-scala
34 | 1.0-SNAPSHOT
35 |
36 |
37 |
38 | javax.inject
39 | javax.inject
40 | 1
41 | provided
42 |
43 |
44 | javax.interceptor
45 | javax.interceptor-api
46 | 1.2
47 |
48 |
49 |
50 | javax.transaction
51 | javax.transaction-api
52 | 1.2
53 |
54 |
55 | junit
56 | junit
57 | 4.11
58 | test
59 |
60 |
61 | org.apache.karaf.features
62 | standard
63 | 4.0.0
64 | features
65 | xml
66 | test
67 |
68 |
69 | org.hibernate
70 | hibernate-annotations
71 | 3.5.6-Final
72 | provided
73 |
74 |
75 | org.hibernate.javax.persistence
76 | hibernate-jpa-2.1-api
77 | 1.0.0.Final
78 |
79 |
80 |
81 | org.mockito
82 | mockito-core
83 | 2.0.31-beta
84 | test
85 |
86 |
87 |
88 | org.ops4j.pax.cdi
89 | pax-cdi-api
90 | 0.5.0
91 | provided
92 |
93 |
94 | org.osgi
95 | org.osgi.core
96 | 6.0.0
97 | provided
98 |
99 |
100 | org.scala-lang
101 | scala-library
102 | 2.11.7
103 | provided
104 |
105 |
106 | org.slf4j
107 | slf4j-api
108 | 1.7.5
109 | provided
110 |
111 |
112 | org.slf4j
113 | slf4j-simple
114 | 1.7.5
115 | provided
116 |
117 |
118 |
119 |
120 |
121 | org.apache.felix
122 | maven-bundle-plugin
123 | 2.3.7
124 | true
125 |
126 |
127 |
128 | !javax.transaction, javax.transaction;version="[1.1,2)", *,
129 | org.hibernate.proxy, javassist.util.proxy
130 | META-INF/persistence.xml
131 |
132 |
133 |
134 |
135 |
136 | maven-surefire-plugin
137 |
138 |
139 | 4.0.1
140 |
141 |
142 |
143 |
144 | org.apache.aries.blueprint
145 | blueprint-maven-plugin
146 | 1.3.0
147 |
148 |
149 | bi.meteorite.core.security.hibernate
150 |
151 |
152 |
153 |
154 |
155 | blueprint-generate
156 |
157 | process-classes
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
--------------------------------------------------------------------------------
/meteorite-persistence/src/main/java/bi/meteorite/core/security/hibernate/EventServiceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security.hibernate;
18 |
19 | import bi.meteorite.core.api.objects.Event;
20 | import bi.meteorite.core.api.persistence.EventService;
21 | import bi.meteorite.objects.EventImpl;
22 |
23 | import org.ops4j.pax.cdi.api.OsgiServiceProvider;
24 | import org.ops4j.pax.cdi.api.Properties;
25 | import org.ops4j.pax.cdi.api.Property;
26 |
27 | import java.util.List;
28 |
29 | import javax.inject.Singleton;
30 | import javax.persistence.EntityManager;
31 | import javax.persistence.PersistenceContext;
32 | import javax.persistence.criteria.CriteriaQuery;
33 | import javax.transaction.Transactional;
34 |
35 | import scala.collection.JavaConversions;
36 |
37 | /**
38 | * Default Event Service Implementation
39 | */
40 | @OsgiServiceProvider(classes = { EventService.class })
41 | @Properties({
42 | @Property(name = "service.exported.interfaces", value = "*")
43 | })
44 | @Singleton
45 | @Transactional
46 | public class EventServiceImpl implements EventService {
47 |
48 | @PersistenceContext(unitName = "systemdbunit")
49 | EntityManager em;
50 |
51 |
52 | @Override
53 | @Transactional(Transactional.TxType.SUPPORTS)
54 | public Event getEventById(String id) {
55 | Event event = em.find(Event.class, id);
56 | return event;
57 | }
58 |
59 | @Override
60 | public Event getEventByUUID(String uuid) {
61 | List result =
62 | (List) em.createQuery("select e from " + EventImpl.class.getName() + " e where uuid = :uuid")
63 | .setParameter("uuid", uuid).getResultList();
64 |
65 | if (result.size() > 0) {
66 | return result.get(0);
67 | }
68 | return null;
69 |
70 | }
71 |
72 | @Override
73 | public scala.collection.immutable.List getEventByEventName(String name) {
74 | List result =
75 | (List) em.createQuery("select e from " + EventImpl.class.getName() + " e where eventName = :ename")
76 | .setParameter("ename", name).getResultList();
77 | if (result.size() > 0) {
78 | //Event e = result.get(0);
79 | //return result;
80 | }
81 | return null;
82 |
83 | }
84 |
85 | @Override
86 | public Event addEvent(Event e) {
87 | em.persist(e);
88 | em.flush();
89 | return e;
90 | }
91 |
92 | @Override
93 | public scala.collection.immutable.List getEvents() {
94 | CriteriaQuery query = em.getCriteriaBuilder().createQuery(EventImpl.class);
95 | List extends Event> list = em.createQuery(query.select(query.from(EventImpl.class))).getResultList();
96 |
97 | return (scala.collection.immutable.List) JavaConversions.asScalaBuffer(list).toList();
98 |
99 | }
100 |
101 |
102 | @Override
103 | public void updateEvent(Event event) {
104 | em.merge(event);
105 | }
106 |
107 | @Override
108 | public void deleteEventById(String id) {
109 | em.remove(getEventById(id));
110 | }
111 |
112 | @Override
113 | public void deleteEventByUUID(String uuid) {
114 | em.remove(getEventByUUID(uuid));
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/meteorite-persistence/src/main/java/bi/meteorite/core/security/hibernate/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security.hibernate;
18 |
19 | import bi.meteorite.core.api.objects.MeteoriteRole;
20 | import bi.meteorite.core.api.objects.MeteoriteUser;
21 | import bi.meteorite.core.api.persistence.UserService;
22 | import bi.meteorite.objects.RoleImpl;
23 | import bi.meteorite.objects.UserImpl;
24 |
25 | import org.ops4j.pax.cdi.api.OsgiServiceProvider;
26 | import org.ops4j.pax.cdi.api.Properties;
27 | import org.ops4j.pax.cdi.api.Property;
28 |
29 | import java.util.List;
30 |
31 | import javax.inject.Singleton;
32 | import javax.persistence.EntityManager;
33 | import javax.persistence.PersistenceContext;
34 | import javax.persistence.criteria.CriteriaQuery;
35 | import javax.transaction.Transactional;
36 |
37 | import scala.collection.Iterable;
38 | import scala.collection.JavaConversions;
39 |
40 | /**
41 | * Implementation for hibernate persistence of users.
42 | */
43 | @OsgiServiceProvider(classes = { UserService.class })
44 | @Properties({
45 | @Property(name = "service.exported.interfaces", value = "*")
46 | })
47 | @Singleton
48 | @Transactional
49 | public class UserServiceImpl implements UserService {
50 |
51 | @PersistenceContext(unitName = "systemdbunit")
52 | EntityManager em;
53 |
54 | @Override
55 | public MeteoriteUser mergeUser(MeteoriteUser u) {
56 | return em.merge(u);
57 | }
58 |
59 | @Override
60 | @Transactional(Transactional.TxType.SUPPORTS)
61 | public MeteoriteUser getUser(String id) {
62 | return em.find(UserImpl.class, id);
63 | }
64 |
65 | @Override
66 | public MeteoriteUser getUser(long id) {
67 | return em.find(UserImpl.class, id);
68 | }
69 |
70 | @Override
71 | public MeteoriteUser addUser(MeteoriteUser user) {
72 | UserImpl u = (UserImpl) user;
73 | em.persist(u);
74 | em.flush();
75 | return u;
76 | }
77 |
78 | @Transactional(Transactional.TxType.SUPPORTS)
79 | @Override
80 | public Iterable getUsers() {
81 | CriteriaQuery query = em.getCriteriaBuilder().createQuery(UserImpl.class);
82 | List collection = em.createQuery(query.select(query.from(UserImpl.class))).getResultList();
83 | return JavaConversions.asScalaBuffer(collection);
84 | }
85 |
86 | @Override
87 | public void updateUser(MeteoriteUser user) {
88 | em.merge(user);
89 | }
90 |
91 | @Override
92 | public void deleteUser(MeteoriteUser id) {
93 | em.remove(getUser(id.getId()));
94 | }
95 |
96 | @Override
97 | public void deleteUser(long id) {
98 | em.remove(getUser(id));
99 | }
100 |
101 | @Override
102 | public MeteoriteRole addRole(MeteoriteRole r) {
103 | RoleImpl u = (RoleImpl) r;
104 | em.persist(u);
105 | em.flush();
106 | return u;
107 | }
108 |
109 | @Override
110 | public void deleteRole(String id) {
111 | em.remove(getRole(id));
112 | }
113 |
114 | @Override
115 | public MeteoriteRole getRole(String id) {
116 | MeteoriteRole r = em.find(RoleImpl.class, id);
117 |
118 | return r;
119 | }
120 |
121 |
122 | public void setEntityManager(EntityManager em) {
123 | this.em = em;
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/meteorite-persistence/src/main/java/bi/meteorite/core/security/hibernate/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * Hibernate stuff..
19 | */
20 | package bi.meteorite.core.security.hibernate;
21 |
--------------------------------------------------------------------------------
/model-scala/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | bi.meteorite
6 | core
7 | 1.0-SNAPSHOT
8 |
9 |
10 | meteorite-core-model-scala
11 | bundle
12 |
13 | Meteorite Core Model
14 | Models for persistence inside Meteorite Core.
15 |
16 |
17 | UTF-8
18 | ../
19 |
20 |
21 |
22 | bi.meteorite
23 | meteorite-core-api
24 | ${version}
25 |
26 |
27 | javax.annotation
28 | jsr250-api
29 |
30 |
31 |
32 |
33 | javax.interceptor
34 | javax.interceptor-api
35 |
36 |
37 | junit
38 | junit
39 | test
40 |
41 |
42 | org.hibernate
43 | hibernate-annotations
44 | provided
45 |
46 |
47 | org.hibernate.javax.persistence
48 | hibernate-jpa-2.1-api
49 |
50 |
51 |
52 | src/main/scala
53 | src/test/scala
54 |
55 |
56 | net.alchim31.maven
57 | scala-maven-plugin
58 | 3.2.1
59 |
60 | 2.11.7
61 |
62 |
63 |
64 |
65 | compile
66 | testCompile
67 |
68 |
69 |
70 |
71 |
72 | org.apache.felix
73 | maven-bundle-plugin
74 | 2.3.7
75 | true
76 |
77 |
78 | bi.meteorite.objects
79 | !javax.transaction, javax.transaction;version="[1.1,2)", *,
80 | org.hibernate.proxy, javassist.util.proxy
81 | META-INF/persistence.xml
82 |
83 |
84 |
85 |
86 |
87 | maven-surefire-plugin
88 |
89 |
90 | 4.0.1
91 |
92 |
93 |
94 |
95 |
96 | http://maven.apache.org
97 |
98 |
--------------------------------------------------------------------------------
/model-scala/src/main/resources/META-INF/persistence.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | org.hibernate.jpa.HibernatePersistenceProvider
8 |
9 |
10 | osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=systemdb)
11 |
12 |
13 | osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=systemdb)
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/model-scala/src/main/scala/bi/meteorite/objects/EventImpl.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.objects
17 |
18 | import bi.meteorite.core.api.objects.Event
19 | import java.util.Date
20 | import javax.persistence.Column
21 | import javax.persistence.Entity
22 | import javax.persistence.GeneratedValue
23 | import javax.persistence.GenerationType
24 | import javax.persistence.Id
25 | import javax.persistence.Lob
26 | import javax.persistence.Table
27 |
28 | /**
29 | * Event Object annotated for persistence.
30 | */
31 | @Entity(name = "EVENTS")
32 | @Table(name = "EVENTS")
33 | class EventImpl extends Event {
34 | @Id
35 | @Column(nullable = false)
36 | @GeneratedValue(strategy = GenerationType.AUTO)
37 | var id: Long = _
38 | @Column
39 | var uuid: String = _
40 | @Column(length = 100)
41 | var className: String = _
42 | @Column(length = 100)
43 | var eventName: String = _
44 | @Column
45 | @Lob
46 | var comment: String = _
47 | @Column(name = "starttime")
48 | @org.hibernate.annotations.Type(`type` = "timestamp")
49 | var startDate: Date = _
50 | @Column(name = "endtime")
51 | @org.hibernate.annotations.Type(`type` = "timestamp")
52 | var endDate: Date = _
53 | @Column
54 | var duration: Long = 0L
55 |
56 |
57 | def this(uuid: String, className: String, eventName: String, comment: String, startDate: Date) {
58 | this()
59 | this.uuid = uuid
60 | this.className = className
61 | this.eventName = eventName
62 | this.comment = comment
63 | this.startDate = startDate
64 | }
65 |
66 | def getId: Long = {
67 | id
68 | }
69 |
70 | def setId(id: Long) {
71 | this.id = id
72 | }
73 |
74 | def getUuid: String = {
75 | uuid
76 | }
77 |
78 | def setUuid(uuid: String) {
79 | this.uuid = uuid
80 | }
81 |
82 | def getClassName: String = {
83 | className
84 | }
85 |
86 | def setClassName(className: String) {
87 | this.className = className
88 | }
89 |
90 | def getEventName: String = {
91 | eventName
92 | }
93 |
94 | def setEventName(eventName: String) {
95 | this.eventName = eventName
96 | }
97 |
98 | def getComment: String = {
99 | comment
100 | }
101 |
102 | def setComment(comment: String) {
103 | this.comment = comment
104 | }
105 |
106 | def getStartDate: Date = {
107 | startDate
108 | }
109 |
110 | def setStartDate(startDate: Date) {
111 | this.startDate = startDate
112 | }
113 |
114 | def getEndDate: Date = {
115 | endDate
116 | }
117 |
118 | def setEndDate(endDate: Date) {
119 | this.endDate = endDate
120 | }
121 |
122 | def getDuration: Long = {
123 | duration
124 | }
125 |
126 | def setDuration(duration: Long) {
127 | this.duration = duration
128 | }
129 |
130 | override def toString: String = {
131 | "EventImpl{" + "id=" + id + ", uuid='" + uuid + '\'' + ", className='" + className + '\'' + ", eventName='" + eventName + '\'' + ", comment='" + comment + '\'' + ", startDate=" + startDate + ", endDate=" + endDate + ", duration=" + duration + '}'
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/model-scala/src/main/scala/bi/meteorite/objects/RoleImpl.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.objects
17 |
18 | import bi.meteorite.core.api.objects.MeteoriteUser
19 | import bi.meteorite.core.api.objects.MeteoriteRole
20 | import javax.persistence._
21 |
22 | import com.fasterxml.jackson.annotation.JsonBackReference
23 |
24 | /**
25 | * Role Object annotated for persistence.
26 | */
27 | @Entity(name = "ROLES")
28 | @Table(name = "ROLES") class RoleImpl extends MeteoriteRole {
29 | @Id
30 | @Column
31 | @TableGenerator(name = "EVENT_GEN2", table = "SEQUENCES2", pkColumnName = "SEQ_NAME2", valueColumnName = "SEQ_NUMBER2", pkColumnValue = "SEQUENCE", allocationSize = 1)
32 | @GeneratedValue(strategy = GenerationType.TABLE, generator = "EVENT_GEN2")
33 | private var id: Int = 0
34 | @ManyToOne(fetch = FetchType.LAZY, cascade = Array(CascadeType.ALL))
35 | @JoinColumn(name = "USER_ID", nullable = false)
36 | @JsonBackReference
37 | private var userid: UserImpl = null
38 | @Column
39 | private var rolename: String = null
40 |
41 | def getId: Int = {
42 | id
43 | }
44 |
45 | def setId(id: Int) {
46 | this.id = id
47 | }
48 |
49 | def getUserId: MeteoriteUser = {
50 | userid
51 | }
52 |
53 | def setUserId(id: MeteoriteUser) {
54 | this.userid = id.asInstanceOf[UserImpl]
55 | }
56 |
57 | def getRole: String = {
58 | rolename
59 | }
60 |
61 | def setRole(role: String) {
62 | this.rolename = role
63 | }
64 |
65 | def this(rolename: String, userid: UserImpl) {
66 | this()
67 | this.rolename = rolename
68 | this.userid = userid
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/model-scala/src/main/scala/bi/meteorite/objects/UserImpl.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.objects
17 |
18 | import javax.persistence._
19 |
20 | import bi.meteorite.core.api.objects.{MeteoriteRole, MeteoriteUser}
21 | import com.fasterxml.jackson.annotation.{JsonInclude, JsonManagedReference}
22 |
23 | /**
24 | * A User Object annotated for persistence
25 | */
26 | @Entity(name = "USERS")
27 | @Table(name = "USERS") class UserImpl extends MeteoriteUser {
28 | @Id
29 | @Column
30 | @TableGenerator(name = "EVENT_GEN", table = "SEQUENCES", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_NUMBER",
31 | pkColumnValue = "SEQUENCE", allocationSize = 1)
32 | @GeneratedValue(strategy = GenerationType.TABLE, generator = "EVENT_GEN")
33 | private var id: Long = _
34 | @Column(length = 100)
35 | private var username: String = _
36 | @Column(length = 100)
37 | private var password: String = _
38 | @JsonInclude(JsonInclude.Include.NON_EMPTY)
39 | @OneToMany(mappedBy = "userid", fetch = FetchType.LAZY, cascade = Array(CascadeType.ALL))
40 | @JsonManagedReference
41 | private val roles: java.util.List[RoleImpl] = new java.util.ArrayList[RoleImpl]()
42 | @Column
43 | private var orgId: Int = _
44 | @Column
45 | private var email: String = _
46 |
47 | def getUsername: String = {
48 | username
49 | }
50 |
51 | def setUsername(username: String) {
52 | this.username = username
53 | }
54 |
55 | def getPassword: String = {
56 | password
57 | }
58 |
59 | def setPassword(password: String) {
60 | this.password = password
61 | }
62 |
63 | //@OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
64 | def getRoles: java.util.List[MeteoriteRole] = {
65 | val l = new java.util.ArrayList[MeteoriteRole]()
66 | import scala.collection.JavaConversions._
67 | for (role <- roles) {
68 | l.add(role)
69 | }
70 | l
71 | }
72 |
73 | def setRoles(roles: java.util.List[MeteoriteRole]) {
74 | import scala.collection.JavaConversions._
75 | if(roles != null) {
76 | for (r <- roles) {
77 | this.roles.add(r.asInstanceOf[RoleImpl])
78 | }
79 | }
80 | }
81 |
82 | def getEmail: String = {
83 | email
84 | }
85 |
86 | def setEmail(email: String) {
87 | this.email = email
88 | }
89 |
90 | def getId: Long = {
91 | id
92 | }
93 |
94 | def setId(id: Long) {
95 | this.id = id
96 | }
97 |
98 | def getOrgId: Int = {
99 | orgId
100 | }
101 |
102 | def setOrgId(orgId: Int) {
103 | this.orgId = orgId
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/security-provider-scala/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | bi.meteorite
6 | core
7 | 1.0-SNAPSHOT
8 |
9 | meteorite-core-security-provider-scala
10 | 1.0-SNAPSHOT
11 | bundle
12 | Meteorite Core Security Provider
13 | The provider of security for Meteorite Core. By Default this is a JAAS implementation and
14 | a hazelcast backed token system.
15 |
16 | 4.6.0
17 | ../
18 |
19 |
20 |
21 | bi.meteorite
22 | meteorite-core-api
23 | ${version}
24 | provided
25 |
26 |
27 | javax.annotation
28 | jsr250-api
29 |
30 |
31 |
32 |
33 | bi.meteorite
34 | meteorite-core-model-scala
35 | ${version}
36 |
37 |
38 | com.google.guava
39 | guava
40 |
41 |
42 | com.hazelcast
43 | hazelcast
44 | provided
45 |
46 |
47 | commons-codec
48 | commons-codec
49 | provided
50 |
51 |
52 | javax.annotation
53 | javax.annotation-api
54 | 1.2
55 |
56 |
57 | javax.inject
58 | javax.inject
59 | provided
60 |
61 |
62 | javax.inject
63 | javax.inject
64 | true
65 |
66 |
67 | javax.servlet
68 | servlet-api
69 | provided
70 |
71 |
72 | javax.transaction
73 | javax.transaction-api
74 |
75 |
76 | junit
77 | junit
78 | test
79 |
80 |
81 | org.apache.aries.blueprint
82 | org.apache.aries.blueprint.annotation.api
83 |
84 |
85 | org.apache.karaf.features
86 | org.apache.karaf.features.core
87 | provided
88 |
89 |
90 |
91 | org.apache.karaf.features
92 | standard
93 | features
94 | xml
95 | test
96 |
97 |
98 | org.apache.karaf.jaas
99 | org.apache.karaf.jaas.boot
100 | provided
101 |
102 |
103 | org.apache.karaf.jaas
104 | org.apache.karaf.jaas.modules
105 | provided
106 |
107 |
108 | org.hibernate
109 | hibernate-annotations
110 | provided
111 |
112 |
113 | org.hibernate.javax.persistence
114 | hibernate-jpa-2.1-api
115 |
116 |
117 | org.mockito
118 | mockito-core
119 | test
120 |
121 |
122 | org.ops4j.pax.cdi
123 | pax-cdi-api
124 | true
125 |
126 |
127 |
128 | org.osgi
129 | org.osgi.core
130 | provided
131 |
132 |
133 | org.scala-lang
134 | scala-library
135 | 2.11.7
136 | provided
137 |
138 |
139 | org.slf4j
140 | slf4j-api
141 | provided
142 |
143 |
144 | org.slf4j
145 | slf4j-simple
146 | provided
147 |
148 |
149 |
150 | src/main/scala
151 | src/test/scala
152 |
153 |
154 | net.alchim31.maven
155 | scala-maven-plugin
156 | 3.2.1
157 |
158 | 2.11.7
159 |
160 |
161 |
162 |
163 | compile
164 | testCompile
165 |
166 |
167 |
168 |
169 |
170 | org.apache.felix
171 | maven-bundle-plugin
172 | 3.0.1
173 | true
174 |
175 |
176 | bi.meteorite.core.security.tokenprovider,bi.meteorite.core.security.jaas
177 | !javax.annotation,*,javax.annotation;version="1.0"
178 |
179 |
180 |
181 |
182 |
183 | org.apache.servicemix.tooling
184 | depends-maven-plugin
185 | 1.2
186 |
187 |
188 | generate-depends-file
189 |
190 | generate-depends-file
191 |
192 |
193 |
194 |
195 |
196 | maven-surefire-plugin
197 |
198 |
199 | 4.0.1
200 |
201 |
202 |
203 |
204 | org.apache.aries.blueprint
205 | blueprint-maven-plugin
206 | 1.3.0
207 |
208 |
209 |
211 |
212 |
213 |
214 |
215 |
216 | blueprint-generate
217 |
218 | process-classes
219 |
220 |
221 |
222 |
223 |
224 |
225 |
--------------------------------------------------------------------------------
/security-provider-scala/src/main/resources/OSGI-INF/blueprint/blueprint.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
52 | datasource = osgi:javax.sql.DataSource/(osgi.jndi.service.name=systemdb)
53 | query.password = SELECT PASSWORD FROM USERS WHERE USERNAME=?
54 | query.role = select ROLENAME from ROLES, USERS where USERS.ID = ROLES.USER_ID and USERNAME = ?
55 | insert.user = INSERT INTO USERS(USERNAME, PASSWORD) VALUES(?,?)
56 | insert.role = INSERT INTO ROLES VALUES(?,?)
57 | delete.user = DELETE FROM USERS WHERE USERNAME=?
58 | delete.role = DELETE FROM ROLES WHERE USERNAME=? AND ROLE=?
59 | delete.roles = DELETE FROM ROLES WHERE USERNAME=?
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/security-provider-scala/src/main/scala/bi/meteorite/core/security/hibernate/DefaultUsers.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security.hibernate
17 |
18 | import bi.meteorite.core.api.objects.Event
19 | import bi.meteorite.core.api.objects.MeteoriteUser
20 | import bi.meteorite.core.api.objects.MeteoriteRole
21 | import bi.meteorite.core.api.persistence.EventService
22 | import bi.meteorite.core.api.persistence.UserService
23 | import bi.meteorite.objects.EventImpl
24 | import bi.meteorite.objects.RoleImpl
25 | import bi.meteorite.objects.UserImpl
26 | import java.util.Date
27 | import java.util.UUID
28 | import javax.annotation.PostConstruct
29 | import scala.collection.JavaConverters._
30 | import scala.collection.mutable.ListBuffer
31 |
32 | /**
33 | * Default Users for demo and initial install purposes.
34 | */
35 | class DefaultUsers {
36 | private var userService: UserService = null
37 | private var eventService: EventService = null
38 |
39 | @PostConstruct def insertUsers() {
40 | if (eventService.getEventByEventName("Start Adding Users") == null) {
41 | val uuid: String = UUID.randomUUID.toString
42 | val e: Event = eventService.addEvent(new EventImpl(uuid, this.getClass.getName, "Start Adding users", "Adding users to user list", new Date))
43 | var u: MeteoriteUser = new UserImpl
44 | u.setUsername("admin")
45 | u.setPassword("admin")
46 | val r: MeteoriteRole = new RoleImpl
47 | r.setUserId(u)
48 | r.setRole("ROLE_ADMIN")
49 | val r2: MeteoriteRole = new RoleImpl
50 | r2.setUserId(u)
51 | r2.setRole("ROLE_USER")
52 | val l = ListBuffer[MeteoriteRole](r, r2)
53 | u.setRoles(l.asJava)
54 | u = userService.addUser(u)
55 |
56 | u = new UserImpl
57 | u.setUsername("smith")
58 | u.setPassword("smith")
59 | val s2 = List[MeteoriteRole](new RoleImpl("ROLE_USER", u.asInstanceOf[UserImpl]))
60 | u.setRoles(s2.asJava)
61 | userService.addUser(u)
62 | e.setEndDate(new Date)
63 | e.setDuration(e.getEndDate.getTime - e.getStartDate.getTime)
64 | eventService.updateEvent(e)
65 | }
66 | }
67 |
68 | def setUserService(userService: UserService) {
69 | this.userService = userService
70 | }
71 |
72 | def setEventService(eventService: EventService) {
73 | this.eventService = eventService
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/security-provider-scala/src/main/scala/bi/meteorite/core/security/jaas/JaasLoginManager.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security.jaas
17 |
18 | import java.io.IOException
19 | import javax.security.auth.Subject
20 | import javax.security.auth.callback.{Callback, CallbackHandler, NameCallback, PasswordCallback, UnsupportedCallbackException}
21 | import javax.security.auth.login.{LoginContext, LoginException}
22 |
23 | import bi.meteorite.core.api.security.AdminLoginService
24 | import org.apache.karaf.jaas.boot.principal.{RolePrincipal, UserPrincipal}
25 | import org.ops4j.pax.cdi.api.OsgiServiceProvider
26 | import org.slf4j.{Logger, LoggerFactory}
27 |
28 | import scala.collection.mutable.ListBuffer
29 |
30 | /**
31 | * Jaas Login Manager
32 | */
33 | @OsgiServiceProvider(classes = Array(classOf[AdminLoginService]))
34 | object JaasLoginManager {
35 | private val LOGGER: Logger = LoggerFactory.getLogger(classOf[JaasLoginManager])
36 | val ROLES_GROUP_NAME: String = "ROLES"
37 | private val ROLES_PREFIX: String = "ROLE_"
38 | }
39 |
40 | @OsgiServiceProvider(classes = Array(classOf[AdminLoginService]))
41 | class JaasLoginManager extends AdminLoginService {
42 | private var realm: String = null
43 | private var subject: Subject = null
44 | private final val roles = new ListBuffer[String]
45 | private var ctx: LoginContext = null
46 |
47 | /**
48 | * Login Callback Handler
49 | */
50 | private class LoginCallbackHandler extends CallbackHandler {
51 | private final var username: String = null
52 | private final var password: String = null
53 |
54 | def this(username: String, password: String) {
55 | this()
56 | this.username = username
57 | this.password = password
58 | }
59 |
60 | @throws(classOf[IOException])
61 | @throws(classOf[UnsupportedCallbackException])
62 | def handle(callbacks: Array[Callback]) {
63 | for (callback <- callbacks) {
64 | callback match {
65 | case callback1: NameCallback =>
66 | callback1.setName(username)
67 | case pwCallback: PasswordCallback =>
68 | pwCallback.setPassword(password.toCharArray)
69 | case _ =>
70 | throw new UnsupportedCallbackException(callback, "Callback type not supported")
71 | }
72 | }
73 | }
74 | }
75 |
76 | def login(username: String, password: String): Boolean = {
77 | var authenticated: Boolean = false
78 | val handler: LoginCallbackHandler = new LoginCallbackHandler(username, password)
79 | try {
80 | if (ctx == null) {
81 | ctx = new LoginContext(realm, handler)
82 | }
83 | ctx.login()
84 | authenticated = true
85 | subject = ctx.getSubject
86 | import scala.collection.JavaConversions._
87 | for (p <- subject.getPrincipals) {
88 | if (p.getName.startsWith(JaasLoginManager.ROLES_PREFIX)) {
89 | roles.add(p.getName.substring(JaasLoginManager.ROLES_PREFIX.length))
90 | }
91 | }
92 | }
93 | catch {
94 | case e: LoginException =>
95 | authenticated = false
96 | }
97 | authenticated
98 | }
99 |
100 | def logout(username: String): Boolean = {
101 | val handler: LoginCallbackHandler = new LoginCallbackHandler(username, null)
102 | try {
103 | if (ctx == null) {
104 | ctx = new LoginContext(realm, handler)
105 | }
106 | ctx.logout()
107 | return true
108 | }
109 | catch {
110 | case e: LoginException =>
111 | e.printStackTrace()
112 | }
113 | false
114 | }
115 |
116 | def getUsername: String = {
117 | val principals = subject.getPrincipals
118 | import scala.collection.JavaConversions._
119 | for (p <- principals) {
120 | if (p.isInstanceOf[UserPrincipal]) {
121 | return p.getName
122 | }
123 | }
124 | null
125 | }
126 |
127 | def getRoles: List[String] = {
128 | val s = new ListBuffer[String]
129 | val principals = subject.getPrincipals
130 | import scala.collection.JavaConversions._
131 | for (p <- principals) {
132 | System.out.println(p.getClass)
133 | JaasLoginManager.LOGGER.debug("Principal type:" + p.getClass)
134 | if (p.isInstanceOf[RolePrincipal]) {
135 | s.add(p.getName)
136 | }
137 | }
138 | s.toList
139 | }
140 |
141 | def setLoginContext(ctx: LoginContext) {
142 | this.ctx = ctx
143 | }
144 |
145 | def setRealm(realm: String) {
146 | this.realm = realm
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/security-provider-scala/src/main/scala/bi/meteorite/core/security/jaas/JaasUserManager.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security.jaas
17 |
18 | import java.security.PrivilegedAction
19 | import java.util.Collections
20 | import javax.inject.{Inject, Named, Singleton}
21 | import javax.security.auth.login.{Configuration, AppConfigurationEntry}
22 |
23 | import bi.meteorite.core.api.objects.{UserList, MeteoriteUser}
24 | import bi.meteorite.core.api.persistence.UserService
25 | import bi.meteorite.core.api.security.IUserManagementProvider
26 | import bi.meteorite.core.api.security.exceptions.MeteoriteSecurityException
27 | import org.apache.karaf.jaas.boot.ProxyLoginModule
28 | import org.apache.karaf.jaas.config.JaasRealm
29 | import org.apache.karaf.jaas.modules.{BackingEngine, BackingEngineFactory, BackingEngineService}
30 | import org.ops4j.pax.cdi.api.{OsgiService, OsgiServiceProvider}
31 | import scala.collection.mutable.ListBuffer
32 | import scala.collection.JavaConversions._
33 |
34 | /**
35 | * Default JaaS User Manager to control users in Karaf.
36 | */
37 | @Singleton
38 | @OsgiServiceProvider(classes = Array(classOf[IUserManagementProvider]))
39 | class JaasUserManager extends IUserManagementProvider {
40 | @Inject
41 | @Named("engineService") private var backingEngineService: BackingEngineService = null
42 | @Inject
43 | @OsgiService private var realm: JaasRealm = null
44 | @Inject
45 | @OsgiService private var userService: UserService = null
46 |
47 | private def getEngine: BackingEngine = {
48 | var config : Configuration = null
49 | if (config == null) {
50 | config = java.security.AccessController.doPrivileged(new PrivilegedAction[Configuration]() {
51 | def run: Configuration = {
52 | Configuration.getConfiguration
53 | }
54 | })
55 | }
56 | var entries2: Array[AppConfigurationEntry] = config.getAppConfigurationEntry("meteorite-realm")
57 | for (entry <- entries2) {
58 | val moduleClass: String = entry.getOptions.get(ProxyLoginModule.PROPERTY_MODULE).asInstanceOf[String]
59 | if (moduleClass != null) {
60 | val factories: BackingEngineFactory = null
61 | val options = entry.getOptions
62 | return backingEngineService.get(entry)
63 | }
64 | }
65 | null
66 | }
67 |
68 | @throws(classOf[MeteoriteSecurityException])
69 | def addUser(u: MeteoriteUser) = getUsersId.contains(u.getId) match {
70 | case true => userService.mergeUser(u)
71 | case false => userService.addUser(u)
72 | }
73 |
74 | @throws(classOf[MeteoriteSecurityException])
75 | def deleteUser(u: MeteoriteUser) = getUsersId.contains(u.getId) match {
76 | case true => userService.deleteUser(u)
77 | case false => throw new MeteoriteSecurityException("User Doesn't Exist")
78 | }
79 |
80 | @throws(classOf[MeteoriteSecurityException])
81 | def deleteUser(u: Long) = getUsersId.contains(u) match {
82 | case true => userService.deleteUser(u)
83 | case false => throw new MeteoriteSecurityException("User Doesn't Exist")
84 | }
85 |
86 |
87 | @throws(classOf[MeteoriteSecurityException])
88 | def getUsers: List[UserList] = (for (user <- userService.getUsers) yield
89 | UserList(user.getId, user.getUsername)).toList
90 |
91 | @throws(classOf[MeteoriteSecurityException])
92 | def getUsersId: List[Long] = (for(user <- userService.getUsers) yield user.getId).toList
93 |
94 |
95 | @throws(classOf[MeteoriteSecurityException])
96 | def getRoles(u: String): List[String] = {
97 | val s = new ListBuffer[String]
98 | val u2 = getUsers
99 | if (u2.contains(u)) {
100 | for (p <- getEngine.listUsers) {
101 | if (p.getName == u) {
102 | for (r <- getEngine.listRoles(p)) {
103 | s.add(r.getName)
104 | }
105 | }
106 | }
107 | s.toList
108 | }
109 | else {
110 | throw new MeteoriteSecurityException("User does not exist")
111 | }
112 | }
113 |
114 | @throws(classOf[MeteoriteSecurityException])
115 | def addRole(u: String, r: String) {
116 | for (p <- getEngine.listUsers) {
117 | if (p.getName == u) {
118 | val roles = getEngine.listRoles(p)
119 | if (roles.size == 0) {
120 | getEngine.addRole(u, r)
121 | }
122 | else {
123 | for (ro <- roles) {
124 | if (!Collections.singletonList(ro).contains(r)) {
125 | getEngine.addRole(u, r)
126 | }
127 | }
128 | }
129 | }
130 | }
131 | }
132 |
133 | @throws(classOf[MeteoriteSecurityException])
134 | def removeRole(u: String, r: String) = getRoles(u).contains(r) match {
135 | case true => getEngine.deleteRole(u, r)
136 | case false => throw new MeteoriteSecurityException("Role does not exist for user")
137 | }
138 |
139 | @throws(classOf[MeteoriteSecurityException])
140 | def updateUser(u: MeteoriteUser): MeteoriteUser = userService.mergeUser(u)
141 |
142 | @throws(classOf[MeteoriteSecurityException])
143 | def isAdmin(u: String): Boolean = {
144 | for (p <- getEngine.listUsers) {
145 | if (p.getName == u) {
146 | val roles = getEngine.listRoles(p)
147 | for (r <- roles) {
148 | if (getAdminRoles.contains(r.getName)) {
149 | return true
150 | }
151 | }
152 | }
153 | }
154 | false
155 | }
156 |
157 | @throws(classOf[MeteoriteSecurityException])
158 | def getAdminRoles: List[String] = {
159 | null
160 | }
161 |
162 | @throws(classOf[MeteoriteSecurityException])
163 | def getUser(id: Long): MeteoriteUser = userService.getUser(id)
164 |
165 | def setBackingEngineService(jassservice: BackingEngineService)= this.backingEngineService = jassservice
166 |
167 | def setRealm(realm: JaasRealm) = this.realm = realm
168 |
169 | def setUserService(userService: UserService) = this.userService = userService
170 | }
171 |
172 |
--------------------------------------------------------------------------------
/security-provider-scala/src/main/scala/bi/meteorite/core/security/tokenprovider/CacheManagerTokenStore.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security.tokenprovider
17 |
18 | import com.hazelcast.core.HazelcastInstance
19 | import org.ops4j.pax.cdi.api.OsgiService
20 | import org.osgi.framework.BundleContext
21 | import org.osgi.framework.wiring.BundleWiring
22 | import org.slf4j.Logger
23 | import org.slf4j.LoggerFactory
24 | import javax.annotation.PostConstruct
25 | import javax.inject.{Named, Inject, Singleton}
26 |
27 | /**
28 | * Token Storage.
29 | */
30 | @Singleton
31 | @Named("CManager")
32 | object CacheManagerTokenStore {
33 | private var logger: Logger = LoggerFactory.getLogger(classOf[CacheManagerTokenStore])
34 | }
35 |
36 | @Singleton class CacheManagerTokenStore extends TokenStorageProvider {
37 | @OsgiService
38 | @Inject private var cacheManager: HazelcastInstance = null
39 | @Inject private var bcontext: BundleContext = null
40 |
41 | @PostConstruct def init {
42 | CacheManagerTokenStore.logger.debug("*** Activating CacheManager")
43 | val c: CompositeClassLoader = new CompositeClassLoader
44 | val tccl: ClassLoader = Thread.currentThread.getContextClassLoader
45 | try {
46 | cacheManager.getConfig.setClassLoader(c)
47 | } finally {
48 | cacheManager.getConfig.setClassLoader(c)
49 | }
50 | }
51 |
52 | def addToken(token: Token) {
53 | addInvokerClassLoader(this.getClass.getClassLoader)
54 | cacheManager.getMap("tokens").put(token.getToken, token)
55 | }
56 |
57 | def updateToken(token: Token) {
58 | }
59 |
60 | def getToken(token: String): Token = {
61 | addInvokerClassLoader(getInvokerClassLoader)
62 | cacheManager.getMap("tokens").get(token).asInstanceOf[Token]
63 | }
64 |
65 | def hasToken(token: String): Boolean = {
66 | addInvokerClassLoader(getInvokerClassLoader)
67 | cacheManager.getMap("tokens").get(token) != null
68 | }
69 |
70 | def removeToken(token: Token) {
71 | }
72 |
73 | def setCacheManagerService(hazel: HazelcastInstance) {
74 | this.cacheManager = hazel
75 | }
76 |
77 | protected def addInvokerClassLoader(cl: ClassLoader) {
78 | getInstance.getConfig.getClassLoader.asInstanceOf[CompositeClassLoader].add(cl)
79 | }
80 |
81 | protected def getInvokerClassLoader: ClassLoader = {
82 | bcontext.getBundle.adapt(classOf[BundleWiring]).getClassLoader
83 | }
84 |
85 | def setBcontext(bcontext: BundleContext) {
86 | this.bcontext = bcontext
87 | }
88 |
89 | def getInstance: HazelcastInstance = {
90 | cacheManager
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/security-provider-scala/src/main/scala/bi/meteorite/core/security/tokenprovider/CompositeClassLoader.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security.tokenprovider
17 |
18 | import java.util
19 | import java.util.Collections
20 |
21 | /**
22 | * CompositeClassLoader For Fixing Bundle Stuff
23 | */
24 | class CompositeClassLoader extends ClassLoader {
25 | private final val classLoaders = Collections.synchronizedList(new util.ArrayList[ClassLoader])
26 |
27 | add(classOf[AnyRef].getClassLoader)
28 | add(getClass.getClassLoader)
29 |
30 |
31 | /**
32 | * Add a loader to the n
33 | *
34 | * @param classLoader The classloader to add.
35 | */
36 | def add(classLoader: ClassLoader) {
37 | if (classLoader != null) {
38 | classLoaders.add(0, classLoader)
39 | }
40 | }
41 |
42 | @throws(classOf[ClassNotFoundException])
43 | override def loadClass(name: String): Class[_] = {
44 | import scala.collection.JavaConversions._
45 | for (classLoader1 <- classLoaders) {
46 | val classLoader: ClassLoader = classLoader1.asInstanceOf[ClassLoader]
47 | try {
48 | return classLoader.loadClass(name)
49 | }
50 | catch {
51 | case notFound: ClassNotFoundException =>
52 | }
53 | }
54 | val contextClassLoader: ClassLoader = Thread.currentThread.getContextClassLoader
55 | if (contextClassLoader != null) {
56 | contextClassLoader.loadClass(name)
57 | }
58 | else {
59 | throw new ClassNotFoundException(name)
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/security-provider-scala/src/main/scala/bi/meteorite/core/security/tokenprovider/Token.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security.tokenprovider
17 |
18 | import bi.meteorite.core.api.security.tokenprovider.IToken
19 | import java.io.Serializable
20 |
21 | import scala.collection.mutable
22 |
23 | /**
24 | * This class represents a generic token. A token is a unique and randomly generated String, associated with a secret
25 | * (which is also a unique and randomly generated String). A timestamp is assigned to a token to facilitate token
26 | * expiration. Arbitrary String properties can be assigned to a token.
27 | */
28 | class Token extends Serializable with IToken {
29 | private var mtoken: String = null
30 | private var mtokenSecret: String = null
31 | private var mtimestamp = 0L
32 | private var mproperties = collection.mutable.Map[String, String]()
33 |
34 | /**
35 | * Constructor. Creates a new token
36 | *
37 | * @param token The uniquely random generated String
38 | * @param tokenSecret The secret, that is supposed to authenticate the owner of the token. The token may be publicly
39 | * available (i.e. send to the client in a http response) but the secret is only known by the
40 | * owner.
41 | * @param timestamp The time at which the token was generated
42 | */
43 | def this(token: String, tokenSecret: String, timestamp: Long) {
44 | this()
45 | mtoken = token
46 | mtokenSecret = tokenSecret
47 | mtimestamp = timestamp
48 | }
49 |
50 | /**
51 | * Returns the token. The token is publicly known.
52 | *
53 | * @return the token.
54 | */
55 | def getToken: String = {
56 | mtoken
57 | }
58 |
59 | /**
60 | * Sets the token.
61 | *
62 | * @param token the token to set
63 | */
64 | def setToken(token: String) {
65 | mtoken = token
66 | }
67 |
68 | /**
69 | * Returns the token secret. The token secret associated with this token is only known by the owner.
70 | *
71 | * @return the secret that only the token owner knows
72 | */
73 | def getTokenSecret: String = {
74 | mtokenSecret
75 | }
76 |
77 | /**
78 | * Sets the token secret.
79 | *
80 | * @param tokenSecret the token secret to set
81 | */
82 | def setTokenSecret(tokenSecret: String) {
83 | mtokenSecret = tokenSecret
84 | }
85 |
86 | /**
87 | * Returns the timestamp in milliseconds of the time at which the token was created.
88 | *
89 | * @return the timestamp in milliseconds
90 | */
91 | def getTimestamp: Long = {
92 | System.currentTimeMillis
93 | mtimestamp
94 | }
95 |
96 | /**
97 | * Sets the timestamp.
98 | *
99 | * @param timestamp the timestamp.
100 | */
101 | def setTimestamp(timestamp: Long) {
102 | mtimestamp = timestamp
103 | }
104 |
105 | /**
106 | * Returns the map of arbitrary properties.
107 | *
108 | * @return a property map.
109 | */
110 | def getProperties: Map[String, String] = {
111 | mproperties.toMap
112 | }
113 |
114 | def getProperty(key: String): String = {
115 | if (mproperties == null) {
116 | return null
117 | }
118 | mproperties.get(key).get
119 | }
120 |
121 | def setProperties(properties: Map[String, String]) {
122 | mproperties = collection.mutable.Map(properties.toSeq: _*)
123 | }
124 |
125 | def setProperty(key: String, value: String) {
126 | if (mproperties == null) {
127 | mproperties = collection.mutable.Map[String, String]()
128 | }
129 | mproperties.put(key, value)
130 | }
131 |
132 | /**
133 | * Verifies if the token is expired comparing its timestamp with the system time. Returns true of the timestamp of
134 | * this token + the provided validity duration equals or is higher then the current time.
135 | *
136 | * @param validityDuration The amount of milliseconds the token is valid. Can be 0. If the validityDuration is smaller
137 | * then 0, this method always returns false.
138 | * @return an expired flag.
139 | */
140 | def isExpired(validityDuration: Long): Boolean = {
141 | if (validityDuration < 0) {
142 | return false
143 | }
144 | else if (validityDuration == 0) {
145 | return true
146 | }
147 | val expiryDate: Long = mtimestamp + validityDuration
148 | System.currentTimeMillis >= expiryDate
149 | }
150 |
151 | override def clone: Token = {
152 | val clone: Token = new Token(mtoken, mtokenSecret, mtimestamp)
153 | if (getProperties != null) {
154 | clone.setProperties(clone.getProperties.toMap)
155 | }
156 | clone
157 | }
158 |
159 | private def clone(map: collection.mutable.Map[String, String]): collection.mutable.Map[String, String] = {
160 | val newMap = collection.mutable.Map[String, String]()
161 | for (key <- map.keySet) {
162 | newMap.put(key, map.get(key).get)
163 | }
164 | newMap
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/security-provider-scala/src/main/scala/bi/meteorite/core/security/tokenprovider/TokenStorageProvider.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security.tokenprovider
17 |
18 | /**
19 | * Token Storage Provider
20 | */
21 | trait TokenStorageProvider {
22 | /**
23 | * Adds a new token to the store.
24 | *
25 | * @param token The token to add
26 | */
27 | def addToken(token: Token)
28 |
29 | /**
30 | * Updates all properties of the token identified by the token key (returned by getToken()). If no token exists with
31 | * this identifier, nothing happens.
32 | *
33 | * @param token the token to update.
34 | */
35 | def updateToken(token: Token)
36 |
37 | /**
38 | * Returns a token from the store.
39 | *
40 | * @param token the token to return from the store.
41 | * @return the token object.
42 | */
43 | def getToken(token: String): Token
44 |
45 | /**
46 | * Returns if this store holds the given token.
47 | *
48 | * @param token The token to verify
49 | * @return true if this store holds this token, false otherwise
50 | */
51 | def hasToken(token: String): Boolean
52 |
53 | /**
54 | * Removes a token from the store.
55 | *
56 | * @param token The token to remove.
57 | */
58 | def removeToken(token: Token)
59 | }
60 |
--------------------------------------------------------------------------------
/security-provider-scala/src/main/scala/bi/meteorite/core/security/tokenprovider/TokenUtil.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security.tokenprovider
17 |
18 | import javax.servlet.http.HttpServletRequest
19 |
20 | import bi.meteorite.core.api.security.tokenprovider.TokenProvider
21 |
22 | /**
23 | * Token Utils
24 | */
25 | object TokenUtil {
26 | /**
27 | * Name of the authorization header when a token is passed in the "Authorization" header of a HTTP request.
28 | */
29 | val AUTHORIZATION_HEADER_AMDATU: String = "Amdatu"
30 |
31 | /**
32 | * Returns the request token associated with the specified request or null of none is associated.
33 | *
34 | * @param request The request to get the token from
35 | * @return the request token associated with the specified request
36 | */
37 | def getTokenFromRequest(request: HttpServletRequest): String = {
38 | if (request.getCookies != null) {
39 | for (cookie <- request.getCookies) {
40 | if (TokenProvider.TOKEN_COOKIE_NAME == cookie.getName) {
41 | return cookie.getValue
42 | }
43 | }
44 | }
45 | val authHeader: String = request.getHeader("Authorization")
46 | if (authHeader != null && authHeader.startsWith(AUTHORIZATION_HEADER_AMDATU + " ")) {
47 | return authHeader.substring(AUTHORIZATION_HEADER_AMDATU.length + 1)
48 | }
49 | null
50 | }
51 | }
52 |
53 | final class TokenUtil {
54 | }
55 |
--------------------------------------------------------------------------------
/security-provider-scala/src/test/java/bi/meteorite/core/security/jaas/TestJaasLoginManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security.jaas;
18 |
19 | import bi.meteorite.core.api.security.AdminLoginService;
20 | import bi.meteorite.core.api.security.IUserManagementProvider;
21 | import bi.meteorite.core.api.security.exceptions.MeteoriteSecurityException;
22 |
23 | import org.apache.felix.utils.properties.Properties;
24 | import org.apache.karaf.jaas.boot.ProxyLoginModule;
25 | import org.apache.karaf.jaas.config.JaasRealm;
26 | import org.apache.karaf.jaas.modules.BackingEngine;
27 | import org.apache.karaf.jaas.modules.BackingEngineFactory;
28 | import org.apache.karaf.jaas.modules.BackingEngineService;
29 | import org.apache.karaf.jaas.modules.properties.PropertiesBackingEngine;
30 |
31 | import com.sun.security.auth.UserPrincipal;
32 |
33 | import org.junit.Before;
34 | import org.junit.Test;
35 | import org.mockito.Mockito;
36 |
37 | import java.util.ArrayList;
38 | import java.util.HashMap;
39 | import java.util.List;
40 | import java.util.Map;
41 |
42 | import javax.security.auth.Subject;
43 | import javax.security.auth.login.AppConfigurationEntry;
44 | import javax.security.auth.login.LoginContext;
45 | import javax.security.auth.login.LoginException;
46 |
47 | import static org.junit.Assert.assertEquals;
48 | import static org.mockito.Mockito.*;
49 |
50 | /**
51 | * JAAS Login Tests.
52 | */
53 | public class TestJaasLoginManager {
54 |
55 | private AdminLoginService jaasLoginManager;
56 |
57 |
58 | @Before
59 | public void setupMockedBackend() {
60 | jaasLoginManager = new JaasLoginManager();
61 | BackingEngineService backingengine = mock(BackingEngineService.class);
62 | JaasRealm realm = mock(JaasRealm.class);
63 | when(realm.getName()).thenReturn("karaf");
64 | AppConfigurationEntry a = mock(AppConfigurationEntry.class);
65 |
66 | Map map = new HashMap<>();
67 | map.put("org.apache.karaf.jaas.module", "mock");
68 | when(a.getOptions().get(ProxyLoginModule.PROPERTY_MODULE)).thenReturn(map);
69 | AppConfigurationEntry[] array = { a };
70 |
71 | when(realm.getEntries()).thenReturn(array);
72 | BackingEngineFactory backingEngineFactory = mock(BackingEngineFactory.class);
73 | BackingEngine be = spy(new PropertiesBackingEngine(new Properties()));
74 | when(backingEngineFactory.build(anyMap())).thenReturn(be);
75 | List l = new ArrayList<>();
76 | l.add(backingEngineFactory);
77 | l.add(backingEngineFactory);
78 | when(backingengine.getEngineFactories()).thenReturn(l);
79 | IUserManagementProvider jaasUserManager = new JaasUserManager();
80 |
81 |
82 | jaasUserManager.setRealm(realm);
83 | jaasUserManager.setBackingEngineService(backingengine);
84 | jaasLoginManager.setRealm(realm.getName());
85 |
86 | LoginContext lcMock = mock(LoginContext.class);
87 |
88 |
89 | Subject s = new Subject();
90 |
91 | s.getPrincipals().add(new UserPrincipal("ROLE_USER"));
92 | s.getPrincipals().add(new UserPrincipal("ROLE_ADMIN"));
93 |
94 |
95 | when(lcMock.getSubject()).thenReturn(s);
96 |
97 | jaasLoginManager.setLoginContext(lcMock);
98 |
99 | // try {
100 | // jaasUserManager.addUser("test", "password");
101 | // } catch (MeteoriteSecurityException e) {
102 | // e.printStackTrace();
103 | // }
104 |
105 | }
106 |
107 | @Test
108 | public void testLogin() throws MeteoriteSecurityException {
109 |
110 | boolean ans = jaasLoginManager.login("test", "password");
111 |
112 | assertEquals(ans, true);
113 | }
114 |
115 | @Test
116 | public void testLoginWrongUsername() throws LoginException {
117 |
118 | failedLogin();
119 |
120 | boolean ans = jaasLoginManager.login("t1est", "password");
121 |
122 | assertEquals(ans, false);
123 | }
124 |
125 | @Test
126 | public void testLoginWrongPassword() throws LoginException {
127 |
128 | failedLogin();
129 |
130 | boolean ans = jaasLoginManager.login("test", "password1");
131 |
132 | assertEquals(ans, false);
133 | }
134 |
135 | @Test
136 | public void testLogout() {
137 | boolean ans = jaasLoginManager.login("test", "password");
138 |
139 | assertEquals(ans, true);
140 |
141 | ans = jaasLoginManager.logout("test");
142 |
143 | assertEquals(ans, true);
144 |
145 | }
146 |
147 | @Test
148 | public void testLogoutWithoutLogin() {
149 |
150 | boolean ans = jaasLoginManager.logout("test");
151 |
152 | assertEquals(ans, true);
153 |
154 | }
155 |
156 |
157 | private void failedLogin() throws LoginException {
158 | LoginContext lcMock = mock(LoginContext.class);
159 |
160 |
161 | Subject s = new Subject();
162 |
163 | s.getPrincipals().add(new UserPrincipal("ROLE_USER"));
164 | s.getPrincipals().add(new UserPrincipal("ROLE_ADMIN"));
165 |
166 |
167 | when(lcMock.getSubject()).thenReturn(s);
168 |
169 | jaasLoginManager.setLoginContext(lcMock);
170 |
171 | Mockito.doThrow(new LoginException("login failed")).when(lcMock).login();
172 |
173 | }
174 |
175 | private void failedLogout() throws LoginException {
176 | LoginContext lcMock = mock(LoginContext.class);
177 |
178 |
179 | Subject s = new Subject();
180 |
181 | s.getPrincipals().add(new UserPrincipal("ROLE_USER"));
182 | s.getPrincipals().add(new UserPrincipal("ROLE_ADMIN"));
183 |
184 |
185 | when(lcMock.getSubject()).thenReturn(s);
186 |
187 | jaasLoginManager.setLoginContext(lcMock);
188 |
189 | Mockito.doThrow(new LoginException("login failed")).when(lcMock).logout();
190 |
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/security-provider-scala/src/test/java/bi/meteorite/core/security/jaas/TestJaasUserManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security.jaas;
18 |
19 | import bi.meteorite.core.api.security.IUserManagementProvider;
20 | import bi.meteorite.core.api.security.exceptions.MeteoriteSecurityException;
21 |
22 | import org.apache.felix.utils.properties.Properties;
23 | import org.apache.karaf.jaas.boot.ProxyLoginModule;
24 | import org.apache.karaf.jaas.config.JaasRealm;
25 | import org.apache.karaf.jaas.modules.BackingEngine;
26 | import org.apache.karaf.jaas.modules.BackingEngineFactory;
27 | import org.apache.karaf.jaas.modules.BackingEngineService;
28 | import org.apache.karaf.jaas.modules.properties.PropertiesBackingEngine;
29 |
30 | import org.junit.Before;
31 | import org.junit.Ignore;
32 | import org.junit.Test;
33 | import org.mockito.Mockito;
34 |
35 | import java.util.ArrayList;
36 | import java.util.HashMap;
37 | import java.util.List;
38 | import java.util.Map;
39 |
40 | import javax.security.auth.login.AppConfigurationEntry;
41 |
42 | import static org.hamcrest.CoreMatchers.equalTo;
43 | import static org.hamcrest.CoreMatchers.hasItem;
44 | import static org.junit.Assert.assertThat;
45 | import static org.mockito.Matchers.anyMap;
46 | import static org.mockito.Mockito.when;
47 |
48 | /**
49 | * JAAS User Management Tests.
50 | */
51 | public class TestJaasUserManager {
52 |
53 | private IUserManagementProvider jaasUserManager;
54 |
55 | @Before
56 | public void setupMockedBackend() {
57 | BackingEngineService backingengine = Mockito.mock(BackingEngineService.class);
58 | JaasRealm realm = Mockito.mock(JaasRealm.class);
59 | AppConfigurationEntry a = Mockito.mock(AppConfigurationEntry.class);
60 |
61 | Map map = new HashMap<>();
62 | map.put("org.apache.karaf.jaas.module", "mock");
63 | when(a.getOptions().get(ProxyLoginModule.PROPERTY_MODULE)).thenReturn(map);
64 | AppConfigurationEntry[] array = { a };
65 |
66 | when(realm.getEntries()).thenReturn(array);
67 | BackingEngineFactory backingEngineFactory = Mockito.mock(BackingEngineFactory.class);
68 | BackingEngine be = Mockito.spy(new PropertiesBackingEngine(new Properties()));
69 | when(backingEngineFactory.build(anyMap())).thenReturn(be);
70 | List l = new ArrayList<>();
71 | l.add(backingEngineFactory);
72 | l.add(backingEngineFactory);
73 | when(backingengine.getEngineFactories()).thenReturn(l);
74 | jaasUserManager = new JaasUserManager();
75 |
76 |
77 | jaasUserManager.setRealm(realm);
78 | jaasUserManager.setBackingEngineService(backingengine);
79 | }
80 |
81 | @Test
82 | public void testAddUser() throws MeteoriteSecurityException {
83 |
84 | jaasUserManager.addUser("test", "password");
85 | assertThat(jaasUserManager.getUsers(), hasItem("test"));
86 |
87 | }
88 |
89 | @Test(expected = MeteoriteSecurityException.class)
90 | public void testAddDuplicateUser() throws MeteoriteSecurityException {
91 |
92 | jaasUserManager.addUser("test", "password");
93 | jaasUserManager.addUser("test", "password");
94 |
95 | }
96 |
97 |
98 | @Test
99 | public void testDeleteUser() throws MeteoriteSecurityException {
100 | jaasUserManager.addUser("test", "password");
101 |
102 | assertThat(jaasUserManager.getUsers().size(), equalTo(1));
103 |
104 | jaasUserManager.deleteUser("test");
105 |
106 | assertThat(jaasUserManager.getUsers().size(), equalTo(0));
107 | }
108 |
109 | @Test(expected = MeteoriteSecurityException.class)
110 | public void testDeleteNonExistentUser() throws MeteoriteSecurityException {
111 | assertThat(jaasUserManager.getUsers().size(), equalTo(0));
112 |
113 |
114 | jaasUserManager.deleteUser("nouser");
115 | }
116 |
117 | @Test
118 | public void testGetRoles() throws MeteoriteSecurityException {
119 |
120 | jaasUserManager.addUser("test", "password");
121 |
122 | assertThat(jaasUserManager.getUsers().size(), equalTo(1));
123 |
124 | jaasUserManager.addRole("test", "testrole");
125 |
126 | assertThat(jaasUserManager.getRoles("test").size(), equalTo(1));
127 |
128 | }
129 |
130 | @Test(expected = MeteoriteSecurityException.class)
131 | public void testGetRolesNonExistentUser() throws MeteoriteSecurityException {
132 | jaasUserManager.addUser("test", "password");
133 |
134 | jaasUserManager.getRoles("nouser");
135 |
136 |
137 | }
138 |
139 | @Test
140 | public void testAddRole() throws MeteoriteSecurityException {
141 | jaasUserManager.addUser("test", "password");
142 |
143 | assertThat(jaasUserManager.getUsers().size(), equalTo(1));
144 |
145 | jaasUserManager.addRole("test", "testrole");
146 |
147 | assertThat(jaasUserManager.getRoles("test").size(), equalTo(1));
148 |
149 |
150 | }
151 |
152 | @Test
153 | public void testDeleteRole() throws MeteoriteSecurityException {
154 | jaasUserManager.addUser("test", "password");
155 |
156 | assertThat(jaasUserManager.getUsers().size(), equalTo(1));
157 |
158 | jaasUserManager.addRole("test", "testrole");
159 |
160 | assertThat(jaasUserManager.getRoles("test").size(), equalTo(1));
161 |
162 | jaasUserManager.removeRole("test", "testrole");
163 |
164 | assertThat(jaasUserManager.getRoles("test").size(), equalTo(0));
165 | }
166 |
167 | @Test(expected = MeteoriteSecurityException.class)
168 | public void testDeleteNonExistentRole() throws MeteoriteSecurityException {
169 | jaasUserManager.addUser("test", "password");
170 |
171 | assertThat(jaasUserManager.getUsers().size(), equalTo(1));
172 |
173 | jaasUserManager.removeRole("test", "testrole");
174 |
175 | }
176 |
177 | @Ignore
178 | @Test
179 | public void testIsAdmin() {
180 |
181 | }
182 |
183 | @Ignore
184 | @Test
185 | public void testIsAdminNonExistentUser() {
186 |
187 | }
188 |
189 |
190 | }
191 |
--------------------------------------------------------------------------------
/security-provider-scala/src/test/java/bi/meteorite/core/security/jaas/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * JAAS Security Implementations.
19 | */
20 | package bi.meteorite.core.security.jaas;
21 |
--------------------------------------------------------------------------------
/security-scala/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | bi.meteorite
6 | core
7 | 1.0-SNAPSHOT
8 |
9 | meteorite-core-security-scala
10 | 1.0-SNAPSHOT
11 | bundle
12 | Meteorite Core Security Management
13 | The security management module for Meteorite Core. This manages the users, groups and
14 | orgs within Meteorite Core.
15 |
16 | ../
17 |
18 |
19 |
20 | bi.meteorite
21 | meteorite-core-api
22 | ${version}
23 |
24 |
25 | javax.annotation
26 | jsr250-api
27 |
28 |
29 |
30 |
31 | bi.meteorite
32 | meteorite-core-model-scala
33 | 1.0-SNAPSHOT
34 |
35 |
36 | com.fasterxml.jackson.core
37 | jackson-annotations
38 | 2.6.2
39 |
40 |
41 | com.fasterxml.jackson.datatype
42 | jackson-datatype-hibernate4
43 | 2.6.2
44 |
45 |
46 |
47 | com.fasterxml.jackson.jaxrs
48 | jackson-jaxrs-json-provider
49 |
50 |
51 | com.fasterxml.jackson.module
52 | jackson-module-scala_2.10
53 | 2.6.2
54 |
55 |
56 | javax.inject
57 | javax.inject
58 | provided
59 |
60 |
61 | javax.servlet
62 | servlet-api
63 | provided
64 |
65 |
66 | javax.ws.rs
67 | javax.ws.rs-api
68 | provided
69 |
70 |
71 | org.apache.cxf
72 | cxf-rt-frontend-jaxrs
73 | provided
74 |
75 |
76 | org.apache.cxf
77 | cxf-rt-rs-security-cors
78 |
79 |
80 | org.apache.karaf.jaas
81 | org.apache.karaf.jaas.boot
82 | provided
83 |
84 |
85 | org.hibernate
86 | hibernate-core
87 | 4.3.5.Final
88 | provided
89 |
90 |
91 | org.ops4j.pax.cdi
92 | pax-cdi-api
93 | provided
94 | true
95 |
96 |
97 | org.osgi
98 | org.osgi.core
99 | provided
100 |
101 |
102 | org.scala-lang
103 | scala-library
104 | 2.11.7
105 | provided
106 |
107 |
108 |
109 | src/main/scala
110 | src/test/scala
111 |
112 |
113 | net.alchim31.maven
114 | scala-maven-plugin
115 | 3.2.1
116 |
117 | 2.11.7
118 |
119 |
120 |
121 |
122 | compile
123 | testCompile
124 |
125 |
126 |
127 |
128 |
129 | org.apache.felix
130 | maven-bundle-plugin
131 | 2.3.7
132 | true
133 |
134 |
135 | bi.meteorite.core.security,bi.meteorite.core.security.rest.objects
136 | !javax.annotation;bi.meteorite.core.security.tokenprovider,javax.xml.bind;version=2.1.0,
137 | javax.xml.bind.annotation;version=2.1.0,
138 | com.sun.xml.bind.v2.runtime.reflect;version=0.0.0;resolution:=optional,*,javax.annotation;version="1.0",com.fasterxml.jackson.annotation,javax.persistence
139 |
140 |
141 |
142 |
143 | org.apache.aries.blueprint
144 | blueprint-maven-plugin
145 | 1.3.0
146 |
147 |
148 | bi.meteorite.core.security
149 | bi.meteorite.core.security.rest
150 | bi.meteorite.core.security.authentication
151 | bi.meteorite.core.security.authorization
152 |
153 |
154 |
155 |
156 |
157 | blueprint-generate
158 |
159 | process-classes
160 |
161 |
162 |
163 |
164 |
165 |
166 |
--------------------------------------------------------------------------------
/security-scala/src/main/resources/OSGI-INF/blueprint/blueprint.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
60 |
61 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/SecurityFilter.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security
18 |
19 | import javax.inject.{Inject, Named, Singleton}
20 | import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
21 | import javax.servlet.{Filter, FilterChain, FilterConfig, ServletRequest, ServletResponse}
22 |
23 | import bi.meteorite.core.api.security.AdminLoginService
24 | import bi.meteorite.core.api.security.exceptions.TokenProviderException
25 | import bi.meteorite.core.api.security.tokenprovider.TokenProvider
26 | import org.ops4j.pax.cdi.api.OsgiService
27 |
28 | /**
29 | * Extended Security Filter for Token Authentication.
30 | */
31 | @Singleton
32 | @Named("securityFilter")
33 | class SecurityFilter extends Filter {
34 |
35 | @Inject
36 | @OsgiService
37 | private var tokenProvider: TokenProvider = _
38 |
39 | @Inject
40 | @OsgiService
41 | private var adminLoginService: AdminLoginService = _
42 |
43 | override def doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain) {
44 | val servletRequest = request.asInstanceOf[HttpServletRequest]
45 | val servletResponse = response.asInstanceOf[HttpServletResponse]
46 | var s = servletRequest.getPathInfo
47 | val s2 = servletRequest.getServletPath
48 | if (s != null && s2 != null) {
49 | s = s2 + s
50 | } else if (s == null) {
51 | s = s2
52 | }
53 | if (s.startsWith("/admin/ui/") || s == "/rest/core/auth/login") {
54 | chain.doFilter(request, response)
55 | } else if (servletRequest.getPathInfo.startsWith("/rest/core/admin")) {
56 | val token = tokenProvider.getTokenFromRequest(servletRequest)
57 | var isAdmin = false
58 | try {
59 | val userDetails = tokenProvider.verifyToken(token)
60 |
61 | if (adminLoginService.getUsername ==
62 | userDetails.get(TokenProvider.USERNAME).get) {
63 | isAdmin = true
64 | }
65 | } catch {
66 | case e: TokenProviderException =>
67 | }
68 | if (isAdmin) {
69 | chain.doFilter(request, response)
70 | } else {
71 | servletResponse.sendRedirect("/admin/ui/index.html")
72 | }
73 | } else {
74 | chain.doFilter(request, response)
75 | }
76 | }
77 |
78 | override def init(arg0: FilterConfig) {
79 | }
80 |
81 | override def destroy() {
82 | }
83 |
84 | def setTokenProvider(tokenProvider: TokenProvider) = this.tokenProvider = tokenProvider
85 |
86 | def setAdminLoginService(adminLoginService: AdminLoginService) = this.adminLoginService = adminLoginService
87 | }
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/UserManager.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security
18 |
19 | import bi.meteorite.core.api.objects.MeteoriteUser
20 | import bi.meteorite.core.api.security.IUserManagement
21 |
22 | /**
23 | * User Manager Endpoints.
24 | */
25 | class UserManager extends IUserManagement {
26 |
27 | override def addUser(u: MeteoriteUser): MeteoriteUser = null
28 |
29 | override def deleteUser(u: MeteoriteUser): Boolean = false
30 |
31 | override def setUser(u: MeteoriteUser): MeteoriteUser = null
32 |
33 | override def getUser(id: Int): MeteoriteUser = null
34 |
35 | override def getRoles(u: MeteoriteUser): Array[String] = {
36 | Array.ofDim[String](0)
37 | }
38 |
39 | override def addRole(u: MeteoriteUser) {
40 | }
41 |
42 | override def removeRole(u: MeteoriteUser) {
43 | }
44 |
45 | override def removeUser(username: String) {
46 | }
47 |
48 | override def updateUser(u: MeteoriteUser): MeteoriteUser = null
49 |
50 | override def isAdmin: Boolean = false
51 |
52 | override def getAdminRoles: List[String] = null
53 | }
54 |
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/authentication/CustomHttpAuthenticationFaultHandler.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security.authentication
18 |
19 | import java.io.IOException
20 | import javax.servlet.http.HttpServletResponse
21 |
22 | import org.apache.cxf.interceptor.security.AuthenticationException
23 | import org.apache.cxf.transport.http.{AbstractHTTPDestination, HttpAuthenticationFaultHandler}
24 | import org.apache.cxf.message.Message
25 |
26 | /**
27 | * HTTP Fault Handler
28 | */
29 | class CustomHttpAuthenticationFaultHandler extends HttpAuthenticationFaultHandler{
30 |
31 | val authenticationType1 = "Basic"
32 | val realm1 = "CXF service"
33 |
34 | override def handleFault(message: Message) {
35 | val ex: Exception = message.getContent(classOf[Exception])
36 | if (ex.isInstanceOf[AuthenticationException]) {
37 | val resp: HttpServletResponse = message.getExchange.getInMessage.get(AbstractHTTPDestination.HTTP_RESPONSE).asInstanceOf[HttpServletResponse]
38 | resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED)
39 | resp.setHeader("WWW-Authenticate", authenticationType1 + " realm=\"" + realm1 + "\"")
40 | resp.setHeader("Access-Control-Allow-Origin", "*")
41 | resp.setContentType("text/plain")
42 |
43 | try {
44 | resp.getWriter.write(ex.getMessage)
45 | resp.getWriter.flush
46 | message.getInterceptorChain.abort
47 | }
48 | catch {
49 | case e: IOException => {
50 | }
51 | }
52 | }
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/authentication/CustomObjectMapper.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security.authentication
18 |
19 | import com.fasterxml.jackson.databind.ObjectMapper
20 | import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module
21 | import com.fasterxml.jackson.module.scala.DefaultScalaModule
22 |
23 | /**
24 | * Extend the default Jackson Object Mapper.
25 | */
26 | class CustomObjectMapper extends ObjectMapper{
27 | this.registerModule(DefaultScalaModule)
28 | this.registerModule(new Hibernate4Module())
29 | }
30 |
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/authentication/TokenAuthenticationFeature.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security.authentication
17 |
18 | import org.apache.cxf.Bus
19 | import org.apache.cxf.feature.AbstractFeature
20 | import org.apache.cxf.interceptor.InterceptorProvider
21 | import org.apache.cxf.interceptor.security.JAASLoginInterceptor
22 |
23 | /**
24 | * Feature to do JAAS authentication with defaults for karaf integration
25 | */
26 | object TokenAuthenticationFeature {
27 | val ID: String = "jaas"
28 | }
29 |
30 | class TokenAuthenticationFeature extends AbstractFeature {
31 | private var contextName: String = "meteorite-realm"
32 | private var reportFault: Boolean = false
33 |
34 | override def getID: String = TokenAuthenticationFeature.ID
35 |
36 | protected override def initializeProvider(provider: InterceptorProvider, bus: Bus) {
37 | val jaasLoginInterceptor: JAASLoginInterceptor = new JAASLoginInterceptor
38 | jaasLoginInterceptor.setRoleClassifierType(JAASLoginInterceptor.ROLE_CLASSIFIER_CLASS_NAME)
39 | jaasLoginInterceptor.setRoleClassifier("org.apache.karaf.jaas.boot.principal.RolePrincipal")
40 | jaasLoginInterceptor.setContextName(contextName)
41 | jaasLoginInterceptor.setReportFault(reportFault)
42 | provider.getInInterceptors.add(jaasLoginInterceptor)
43 | super.initializeProvider(provider, bus)
44 | }
45 |
46 | def setContextName(contextName: String) = this.contextName = contextName
47 |
48 | def setReportFault(reportFault: Boolean) = this.reportFault = reportFault
49 | }
50 |
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/authentication/TokenJAASAuthenticationFilter.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security.authentication
18 |
19 | import java.security.{AccessController, Principal}
20 | import javax.annotation.Priority
21 | import javax.security.auth.Subject
22 | import javax.security.auth.callback.{CallbackHandler, NameCallback}
23 | import javax.ws.rs.Priorities
24 | import javax.ws.rs.container.{ContainerRequestContext, PreMatching}
25 | import javax.ws.rs.core.SecurityContext
26 |
27 | import bi.meteorite.core.api.security.exceptions.TokenProviderException
28 | import bi.meteorite.core.api.security.tokenprovider.TokenProvider
29 | import org.apache.cxf.interceptor.security.JAASLoginInterceptor
30 | import org.apache.cxf.interceptor.security.callback.{CallbackHandlerProvider, CallbackHandlerProviderAuthPol, CallbackHandlerProviderUsernameToken}
31 | import org.apache.cxf.jaxrs.security.JAASAuthenticationFilter
32 | import org.apache.cxf.jaxrs.utils.JAXRSUtils
33 | import org.apache.cxf.message.Message
34 | import org.apache.karaf.jaas.boot.principal.RolePrincipal
35 |
36 | import scala.collection.JavaConversions._
37 | import scala.collection.immutable.TreeMap
38 |
39 | /**
40 | * Token Authentication filter for JAAS
41 | */
42 | @PreMatching
43 | @Priority(Priorities.AUTHENTICATION)
44 | class TokenJAASAuthenticationFilter extends JAASAuthenticationFilter {
45 |
46 |
47 | private val interceptor = new JAASLoginInterceptor() {
48 |
49 | override protected def getCallbackHandler(name: String, password: String): CallbackHandler = {
50 | TokenJAASAuthenticationFilter.this.getCallbackHandler(name, password)
51 | }
52 |
53 | }
54 |
55 | private var tokenProvider: TokenProvider = _
56 |
57 | private var oldcontext: SecurityContext = _
58 |
59 | private val callbackHandlerProviders = List[CallbackHandlerProvider](new CallbackHandlerProviderAuthPol(), new CallbackHandlerProviderUsernameToken())
60 |
61 | interceptor.setUseDoAs(false)
62 |
63 | interceptor.setContextName("meteorite-realm")
64 |
65 | interceptor.setRoleClassifierType(JAASLoginInterceptor.ROLE_CLASSIFIER_CLASS_NAME)
66 | interceptor.setRoleClassifier("org.apache.karaf.jaas.boot.principal.RolePrincipal")
67 | interceptor.setReportFault(true)
68 |
69 | override def filter(context: ContainerRequestContext) {
70 | val m = JAXRSUtils.getCurrentMessage
71 | try {
72 | var valid: collection.SortedMap[String, String] = null
73 | val cookies = context.getCookies
74 | if (cookies.containsKey(TokenProvider.TOKEN_COOKIE_NAME)) {
75 | try {
76 | val cookie = cookies.get(TokenProvider.TOKEN_COOKIE_NAME)
77 | valid = tokenProvider.verifyToken(cookie.getValue)
78 | val finalValid = valid
79 | val c = new SecurityContext() {
80 |
81 | val p = new UserPrincipal(finalValid.get(TokenProvider.USERNAME).get)
82 |
83 | override def getUserPrincipal: Principal = p
84 |
85 | override def isUserInRole(role: String): Boolean = {
86 | val rolearray = finalValid.get(TokenProvider.ROLES).get.split(",")
87 | rolearray contains role
88 | }
89 |
90 | override def isSecure: Boolean = false
91 |
92 | override def getAuthenticationScheme: String = null
93 | }
94 | oldcontext = context.getSecurityContext
95 | context.setSecurityContext(c)
96 | m.put(classOf[SecurityContext], c);
97 | } catch {
98 | case e: TokenProviderException => context.setSecurityContext(oldcontext)
99 | }
100 | }
101 | if (valid == null || valid.isEmpty) {
102 | val handler = getFirstCallbackHandler(m)
103 | interceptor.handleMessage(m)
104 | val o = m.get(classOf[org.apache.cxf.security.SecurityContext])
105 | var obj = o match {
106 | case o2: org.apache.cxf.interceptor.security.RolePrefixSecurityContextImpl => o2
107 | case _ => throw new ClassCastException
108 | }
109 |
110 |
111 |
112 |
113 | val acc = AccessController.getContext
114 | val subject = obj.getSubject
115 | val principals = subject.getPrincipals
116 | var s = ""
117 | for (role <- principals if role.isInstanceOf[RolePrincipal]) {
118 | s += role.getName + ","
119 | }
120 | if(s.length>0) {
121 | s = s.substring(0, s.length - 1)
122 | }
123 | var userMap = new TreeMap[String, String]()
124 | userMap += (TokenProvider.USERNAME -> getUsername(handler))
125 | userMap += (TokenProvider.ROLES -> s)
126 | try {
127 | val token = tokenProvider.generateToken(userMap)
128 | context.setProperty("token", token)
129 | } catch {
130 | case e: TokenProviderException => e.printStackTrace()
131 | }
132 | }
133 | } catch {
134 | case ex: SecurityException => context.abortWith(handleAuthenticationException(ex, m))
135 | }
136 | }
137 |
138 | private def getUsername(handler: CallbackHandler): String = {
139 | if (handler == null) {
140 | return null
141 | }
142 | try {
143 | val usernameCallBack = new NameCallback("user")
144 | handler.handle(Array(usernameCallBack))
145 | usernameCallBack.getName
146 | } catch {
147 | case e: Exception => null
148 | }
149 | }
150 |
151 | private def getFirstCallbackHandler(message: Message): CallbackHandler = {
152 | for (cbp <- callbackHandlerProviders) {
153 | val cbh = cbp.create(message)
154 | if (cbh != null) {
155 | return cbh
156 | }
157 | }
158 | null
159 | }
160 |
161 | def setTokenProvider(tokenProvider: TokenProvider) {
162 | this.tokenProvider = tokenProvider
163 | }
164 |
165 | class UserPrincipal(val name: String) extends Principal{
166 |
167 | override def getName: String = name
168 |
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/authentication/TokenResponseFilter.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security.authentication
18 |
19 | import javax.inject.{Named, Singleton}
20 | import javax.ws.rs.container.{ContainerRequestContext, ContainerResponseContext, ContainerResponseFilter}
21 | import javax.ws.rs.core.{HttpHeaders, NewCookie}
22 |
23 | import bi.meteorite.core.api.security.tokenprovider.TokenProvider
24 |
25 | /**
26 | * Token Response Filter for JAAS.
27 | */
28 | @Singleton
29 | @Named("tokenResponseFilter")
30 | class TokenResponseFilter extends ContainerResponseFilter {
31 |
32 | override def filter(requestContext: ContainerRequestContext, responseContext: ContainerResponseContext) {
33 | val value = requestContext.getProperty("token").asInstanceOf[String]
34 | if (value != null) {
35 | val newcookie = new NewCookie(TokenProvider.TOKEN_COOKIE_NAME, value)
36 | responseContext.getHeaders.putSingle(HttpHeaders.SET_COOKIE, newcookie)
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/authorization/TokenAbstractAutorizingInInterceptor.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security.authorization
17 |
18 | import java.lang.reflect.Method
19 | import java.util
20 | import java.util.logging.Level
21 |
22 | import org.apache.cxf.common.logging.LogUtils
23 | import org.apache.cxf.interceptor.security.{AbstractAuthorizingInInterceptor, AccessDeniedException}
24 | import org.apache.cxf.message.Message
25 | //remove if not needed
26 | import scala.collection.JavaConversions._
27 |
28 | object TokenAbstractAutorizingInInterceptor {
29 |
30 | private val LOG = LogUtils.getL7dLogger(classOf[TokenAbstractAutorizingInInterceptor])
31 |
32 | private val ALL_ROLES = "*"
33 | }
34 |
35 | /**
36 | * Abstract token interceptor class.
37 | * @param uniqueId
38 | */
39 | abstract class TokenAbstractAutorizingInInterceptor(uniqueId: Boolean) extends AbstractAuthorizingInInterceptor(uniqueId) {
40 |
41 | def this() {
42 | this(true)
43 | }
44 |
45 | override def handleMessage(message: Message) {
46 | val method = getTargetMethod(message)
47 | val sc = message.get(classOf[javax.ws.rs.core.SecurityContext])
48 | if (sc == null) {
49 | val sc2 = message.get(classOf[org.apache.cxf.security.SecurityContext])
50 | if (authorize(sc2, method)) {
51 | return
52 | }
53 | } else if (sc.getUserPrincipal != null) {
54 | if (authorize(sc, method)) {
55 | return
56 | }
57 | } else if (!isMethodProtected(method) && isAllowAnonymousUsers) {
58 | return
59 | }
60 | throw new AccessDeniedException("Unauthorized")
61 | }
62 |
63 | protected def authorize(sc: javax.ws.rs.core.SecurityContext, method: Method): Boolean = {
64 | val expectedRoles = getExpectedRoles(method)
65 | if (expectedRoles.isEmpty) {
66 | val denyRoles = getDenyRoles(method)
67 | return denyRoles.isEmpty || isUserInRole(sc, denyRoles, deny = true)
68 | }
69 | if (isUserInRole(sc, expectedRoles, deny = false)) {
70 | return true
71 | }
72 | if (TokenAbstractAutorizingInInterceptor.LOG.isLoggable(Level.FINE)) {
73 | TokenAbstractAutorizingInInterceptor.LOG.fine(sc.getUserPrincipal.getName + " is not authorized")
74 | }
75 | false
76 | }
77 |
78 |
79 | protected def isUserInRole(sc: javax.ws.rs.core.SecurityContext, roles: util.List[String], deny: Boolean): Boolean = {
80 | if (roles.size == 1 && TokenAbstractAutorizingInInterceptor.ALL_ROLES == roles.get(0)) {
81 | return !deny
82 | }
83 | for (role <- roles if sc.isUserInRole(role)) {
84 | return !deny
85 | }
86 | deny
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/authorization/TokenAuthorizingFilter.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security.authorization
18 |
19 | import javax.annotation.Priority
20 | import javax.inject.{Inject, Named, Singleton}
21 | import javax.ws.rs.Priorities
22 | import javax.ws.rs.container.{ContainerRequestContext, ContainerRequestFilter}
23 | import javax.ws.rs.core.Response
24 |
25 | import org.apache.cxf.interceptor.security.AccessDeniedException
26 | import org.apache.cxf.jaxrs.utils.JAXRSUtils
27 |
28 | /**
29 | * Authorizing filter for Token Authentication.
30 | */
31 | @Priority(Priorities.AUTHORIZATION)
32 | @Singleton
33 | @Named("authorizationFilter")
34 | class TokenAuthorizingFilter extends ContainerRequestFilter {
35 |
36 | @Inject
37 | @Named("authorizationInterceptor")
38 | private var interceptor: TokenAuthorizingInterceptor = null
39 |
40 | def filter(context: ContainerRequestContext) = {
41 | try {
42 | interceptor.handleMessage(JAXRSUtils.getCurrentMessage)
43 | }
44 | catch {
45 | case _: AccessDeniedException => context.abortWith(Response.status(Response.Status.FORBIDDEN).build)
46 | }
47 |
48 | }
49 |
50 | def setInterceptor(in: TokenAuthorizingInterceptor) = interceptor = in
51 | }
52 |
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/authorization/TokenAuthorizingInterceptor.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security.authorization
18 |
19 | import java.lang.reflect.Method
20 | import org.apache.cxf.security.SecurityContext
21 |
22 | import java.util
23 |
24 | import scala.collection.mutable.HashMap
25 | import scala.collection.mutable.ListBuffer
26 |
27 | import scala.collection.JavaConversions._
28 | import TokenAuthorizingInterceptor._
29 | import scala.collection.JavaConverters._
30 |
31 | object TokenAuthorizingInterceptor {
32 |
33 | private def parseRolesMap(rolesMap: Map[String, String]): scala.collection.mutable.HashMap[String, List[String]] = {
34 | val map = new scala.collection.mutable.HashMap[String, List[String]]()
35 | for ((key, value) <- rolesMap) {
36 | map.put(key, value.split(" ").toList)
37 | }
38 | map
39 | }
40 | }
41 |
42 | /**
43 | * Token Interceptor for JAAS authentication.
44 | * @param uniqueId
45 | */
46 | class TokenAuthorizingInterceptor(uniqueId: Boolean) extends TokenAbstractAutorizingInInterceptor(uniqueId) {
47 |
48 | private val methodRolesMap = new HashMap[String, List[String]]()
49 |
50 | private var userRolesMap = new scala.collection.mutable.HashMap[String, List[String]]
51 |
52 | private var globalRoles = new scala.collection.mutable.ListBuffer[String]
53 |
54 | private var checkConfiguredRolesOnly: Boolean = _
55 |
56 | def this() {
57 | this(true)
58 | }
59 |
60 | protected override def isUserInRole(sc: SecurityContext, roles: util.List[String], deny: Boolean): Boolean = {
61 | if (!checkConfiguredRolesOnly && !super.isUserInRole(sc, roles, deny)) {
62 | return false
63 | }
64 | if (userRolesMap.nonEmpty) {
65 | val userRoles = userRolesMap.get(sc.getUserPrincipal.getName)
66 | if (userRoles == null) {
67 | return false
68 | }
69 | for (role <- roles if userRoles.get.contains(role)) {
70 | return true
71 | }
72 | false
73 | } else {
74 | !checkConfiguredRolesOnly
75 | }
76 | }
77 |
78 | private def createMethodSig(method: Method): String = {
79 | val b = new StringBuilder(method.getReturnType.getName)
80 | b.append(' ').append(method.getName).append('(')
81 | for (cls <- method.getParameterTypes) {
82 | b.append(cls.getName)
83 | }
84 | b.append(')')
85 | b.toString
86 |
87 | method.getName
88 | }
89 |
90 | protected override def getExpectedRoles(method: Method): util.List[String] = {
91 |
92 | var roles = methodRolesMap.get(createMethodSig(method))
93 |
94 | if(roles.isEmpty) {
95 | roles = methodRolesMap.get(method.getName)
96 | }
97 |
98 | if(roles.isEmpty){
99 | globalRoles.toList
100 | }
101 | else{
102 | roles.get
103 | }
104 |
105 | }
106 |
107 | def setMethodRolesMap(rolesMap: java.util.Map[String, String]) =
108 | methodRolesMap.putAll(parseRolesMap(rolesMap.asScala.toMap))
109 |
110 | def setUserRolesMap(rolesMap: java.util.Map[String, String]) = userRolesMap = parseRolesMap(rolesMap.asScala.toMap)
111 |
112 | def setGlobalRoles(roles: String) = globalRoles = roles.split(" ").to[ListBuffer]
113 |
114 | def setCheckConfiguredRolesOnly(checkConfiguredRolesOnly: Boolean) = this.checkConfiguredRolesOnly =
115 | checkConfiguredRolesOnly
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/rest/UserAuthenticationImpl.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security.rest
17 |
18 | import javax.inject.{Inject, Singleton}
19 | import javax.ws.rs.core.Response
20 |
21 | import bi.meteorite.core.api.security.AdminLoginService
22 | import bi.meteorite.core.api.security.rest.{UserAuthentication, UserService}
23 | import org.ops4j.pax.cdi.api.{OsgiService, OsgiServiceProvider}
24 |
25 | /**
26 | * User Authentication endpoints.
27 | */
28 | @OsgiServiceProvider(classes = Array(classOf[UserAuthentication]))
29 | @Singleton class UserAuthenticationImpl extends UserAuthentication {
30 |
31 | @Inject
32 | @volatile
33 | @OsgiService
34 | private var adminLoginService: AdminLoginService = null
35 |
36 | override def logout(username: String) : Response = {
37 | if(adminLoginService.logout(username)){
38 | Response.ok().build()
39 | }
40 | else{
41 | Response.serverError().build()
42 | }
43 | }
44 |
45 | def setAdminLoginService(adminLoginService: AdminLoginService) = this.adminLoginService = adminLoginService
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/rest/UserServiceImpl.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package bi.meteorite.core.security.rest
18 |
19 | import javax.inject.{Inject, Named, Singleton}
20 | import javax.ws.rs.core.Response
21 |
22 | import bi.meteorite.core.security.rest.objects.UserObj
23 | import bi.meteorite.objects.UserImpl
24 |
25 | import scala.collection.JavaConverters._
26 |
27 | import bi.meteorite.core.api.objects.MeteoriteUser
28 | import bi.meteorite.core.api.security.IUserManagementProvider
29 | import bi.meteorite.core.api.security.rest.UserService
30 | import org.ops4j.pax.cdi.api.{OsgiService, OsgiServiceProvider}
31 |
32 | /**
33 | * User Service Endpoints.
34 | */
35 | @OsgiServiceProvider(classes = Array(classOf[UserService]))
36 | @Singleton
37 | @Named("userRestServiceBean")
38 | class UserServiceImpl extends UserService {
39 |
40 | @Inject
41 | @OsgiService
42 | private var iUserManagementProvider: IUserManagementProvider = _
43 |
44 | override def addUser(u: MeteoriteUser): Response = {
45 | iUserManagementProvider.addUser(u.asInstanceOf[UserObj].toUserImpl())
46 | Response.ok(u).build()
47 | }
48 |
49 | override def modifyUser(u: MeteoriteUser): Response = Response.ok(iUserManagementProvider.updateUser(u)).build()
50 |
51 | override def deleteUser(u: MeteoriteUser): Response = {
52 | iUserManagementProvider.deleteUser(u)
53 | Response.ok().build()
54 | }
55 |
56 | override def deleteUser(id: Int): Response = {
57 | iUserManagementProvider.deleteUser(id)
58 | Response.ok().build()
59 | }
60 |
61 | override def addRole(id: String, group: Int): Response = Response.serverError().build()
62 |
63 | override def addRole(id: String, group: String): Response = {
64 | iUserManagementProvider.addRole(id, group)
65 | Response.ok().build()
66 | }
67 |
68 | override def getExistingUsers: Response = Response.ok(iUserManagementProvider.getUsers.asJava).build()
69 |
70 | override def getUser(id: Int): Response = Response.ok(iUserManagementProvider.getUser(id)).build()
71 |
72 |
73 | override def whoami: Response = Response.ok("{\"login\":{\"password\":\"pass\",\"username\":\"test3\"}}").build()
74 |
75 | def setiUserManagementProvider(iUserManagementProvider: IUserManagementProvider) = this.iUserManagementProvider =
76 | iUserManagementProvider
77 |
78 | }
--------------------------------------------------------------------------------
/security-scala/src/main/scala/bi/meteorite/core/security/rest/objects/UserObj.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package bi.meteorite.core.security.rest.objects
17 |
18 | import bi.meteorite.core.api.objects.{MeteoriteRole, MeteoriteUser}
19 | import bi.meteorite.objects.UserImpl
20 |
21 | /**
22 | * A User Object for Jackson
23 | */
24 | class UserObj extends MeteoriteUser {
25 | private var id: Long = 0
26 | private var username: String = null
27 | private var password: String = null
28 | //private val roles: java.util.List[RoleImpl] = new java.util.ArrayList[RoleImpl]()
29 | private var orgId: Int = 0
30 | private var email: String = null
31 |
32 | def getUsername: String = {
33 | username
34 | }
35 |
36 | def setUsername(username: String) {
37 | this.username = username
38 | }
39 |
40 | def getPassword: String = {
41 | password
42 | }
43 |
44 | def setPassword(password: String) {
45 | this.password = password
46 | }
47 |
48 | def getRoles: java.util.List[MeteoriteRole] = {
49 | null
50 | }
51 |
52 | def setRoles(roles: java.util.List[MeteoriteRole]) {
53 | }
54 |
55 | def getEmail: String = {
56 | email
57 | }
58 |
59 | def setEmail(email: String) {
60 | this.email = email
61 | }
62 |
63 | def getId: Long = {
64 | id
65 | }
66 |
67 | def setId(id: Long) {
68 | this.id = id
69 | }
70 |
71 | def getOrgId: Int = {
72 | orgId
73 | }
74 |
75 | def setOrgId(orgId: Int) {
76 | this.orgId = orgId
77 | }
78 |
79 |
80 | def toUserImpl(): UserImpl ={
81 | var u = new UserImpl
82 | u.setId(this.getId)
83 | u.setEmail(this.getEmail)
84 | u.setOrgId(this.getOrgId)
85 | u.setPassword(this.getPassword)
86 | u.setRoles(this.getRoles)
87 | u.setUsername(this.getUsername)
88 |
89 | u
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/config/checkstyle/header.txt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 OSBI Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
--------------------------------------------------------------------------------
/src/main/config/checkstyle/suppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------