Beginning Java EE 7 by Antonio Goncalves

Beginning Java EE 7 by Antonio Goncalves

Author:Antonio Goncalves
Language: eng
Format: epub, pdf
ISBN: 9781430246268
Publisher: Apress


Listing 8-9. A Bean Using Programmatic Security

@Stateless

public class ItemEJB {

@PersistenceContext(unitName = "chapter08PU")

private EntityManager em;

@Resource

private SessionContext ctx ;

public void deleteBook(Book book) {

if (!ctx. isCallerInRole ("admin"))

throw new SecurityException("Only admins are allowed");

em.remove(em.merge(book));

}

public Book createBook(Book book) {

if (ctx. isCallerInRole ("employee") && !ctx. isCallerInRole ("admin")) {

book.setCreatedBy("employee only");

} else if (ctx. getCallerPrincipal ().getName().equals("paul")) {

book.setCreatedBy("special user");

}

em.persist(book);

return book;

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.