https://github.com/bednar/security
Java Security Library
https://github.com/bednar/security
Last synced: about 1 month ago
JSON representation
Java Security Library
- Host: GitHub
- URL: https://github.com/bednar/security
- Owner: bednar
- License: bsd-2-clause
- Created: 2013-10-26T09:01:50.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-12-17T17:08:22.000Z (over 12 years ago)
- Last Synced: 2025-03-02T07:44:19.679Z (over 1 year ago)
- Language: Java
- Homepage: https://github.com/bednar/security
- Size: 355 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Security Library
====
[](https://travis-ci.org/bednar/security) [](https://coveralls.io/r/bednar/security)
## Authorize Persist Events
Persist events -
[save](https://github.com/bednar/persistence/blob/master/src/main/java/com/github/bednar/persistence/event/SaveEvent.java),
[read](https://github.com/bednar/persistence/blob/master/src/main/java/com/github/bednar/persistence/event/ReadEvent.java),
[delete](https://github.com/bednar/persistence/blob/master/src/main/java/com/github/bednar/persistence/event/DeleteEvent.java),
[list](https://github.com/bednar/persistence/blob/master/src/main/java/com/github/bednar/persistence/event/ListEvent.java)
are protected by [authorization subquery](https://github.com/bednar/security/blob/master/src/main/java/com/github/bednar/security/contract/ResourceAuthorize.java).
### Create New
Criterion for select [Authenticable Resource](https://github.com/bednar/security/blob/master/src/main/java/com/github/bednar/security/contract/Authenticable.java) which can create `Chat Room`.
/**
* Only account with principal (unique user identifier) Admin can create new Chat Room
*/
@Nonnull
public Criterion createNew(@Nonnull final String principal)
{
return Restrictions.eq("account", "admin");
}
### Update
Criterion for select `Resources` which can `principal` update.
/**
* Principal (unique user identifier) can update Chat Rooms where is admin.
*/
@Nonnull
public Criterion update(@Nonnull final String principal)
{
return Restrictions.eq("admin", principal);
}
### Read
Criterion for select `Resources` which can `principal` read (list).
/**
* Principal (unique user identifier) can read Chat Rooms where is admin or is subscribed to in.
*/
@Nonnull
public Criterion read(@Nonnull final String principal)
{
DetachedCriteria subscribers = DetachedCriteria
.forClass(ChatRoomUserAssoc.class, "roomUser")
.setProjection(Property.forName("chat.id"))
.add(Restrictions.eq("user", principal));
return Restrinctions.or(
Restrictions.eq("admin", principal),
Subqueries.propertyIn("id", subscribers)
);
}
### Delete
Criterion for select `Resources` which can `principal` delete.
/**
* Principal (unique user identifier) can delete Chat Rooms where is admin.
*/
@Nonnull
public Criterion delete(@Nonnull final String principal)
{
return Restrictions.eq("admin", principal);
}
## Security Annotation for API Resource
### RequiresAuthentication
[RequiresAuthentication](http://shiro.apache.org/static/current/apidocs/org/apache/shiro/authz/annotation/RequiresAuthentication.html)
from [Shiro](http://shiro.apache.org) can be use for annotate API Resource method which require authenticated Subject.
@Path("/account")
public class AccountResource implements ApiResource
{
@GET
@Path("/me")
@RequiresAuthentication
public void me(@Nonnull @Suspend final AsynchronousResponse response)
{
//Subject is authenticated => generate regular response
response.setResponse(...);
}
}
## Maven Repository
public
Public
http://nexus-bednar.rhcloud.com/nexus/content/groups/public/
## License
Copyright (c) 2013, Jakub Bednář
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.