Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.github.sobolewskikamil.soa.service.soap;
- import com.github.sobolewskikamil.soa.persistence.api.model.CategoryType;
- import com.github.sobolewskikamil.soa.persistence.api.model.ElementType;
- import com.github.sobolewskikamil.soa.persistence.api.remote.CategoryTypeDao;
- import com.github.sobolewskikamil.soa.persistence.api.remote.OwnerDao;
- import javax.annotation.Resource;
- import javax.ejb.EJB;
- import javax.jws.WebService;
- import javax.xml.ws.BindingProvider;
- import javax.xml.ws.WebServiceContext;
- import javax.xml.ws.handler.MessageContext;
- import java.util.List;
- import java.util.Map;
- @WebService(endpointInterface = "com.github.sobolewskikamil.soa.service.soap.CategoryTypeDao")
- public class CategoryTypeDaoImpl implements com.github.sobolewskikamil.soa.service.soap.CategoryTypeDao {
- @EJB(mappedName = "java:global/soa-project-persistence-server/CategoryTypeDao!com.github.sobolewskikamil.soa.persistence.api.remote.CategoryTypeDao")
- private CategoryTypeDao categoryTypeDao;
- @EJB(mappedName = "java:global/soa-project-persistence-server/OwnerDao!com.github.sobolewskikamil.soa.persistence.api.remote.OwnerDao")
- private OwnerDao ownerDao;
- @Resource
- private WebServiceContext webServiceContext;
- @Override
- public void addCategoryType(String categoryTypeName, String categoryTypePropertyName, String elementTypeName, String elementTypePropertyName1, String elementTypePropertyName2, String elementTypePropertyName3, String elementTypePropertyName4) {
- if (isUserValid()) {
- ElementType elementType = new ElementType()
- .withName(elementTypeName)
- .withPropertyName1(elementTypePropertyName1)
- .withPropertyName2(elementTypePropertyName2)
- .withPropertyName3(elementTypePropertyName3)
- .withPropertyName4(elementTypePropertyName4);
- CategoryType categoryType = new CategoryType()
- .withName(categoryTypeName)
- .withPropertyName(categoryTypePropertyName)
- .withElementTypeById(elementType);
- categoryTypeDao.addCategoryType(categoryType);
- } else {
- throw new RuntimeException(new IllegalAccessException("Authentication failed"));
- }
- }
- private boolean isUserValid() {
- MessageContext messageContext = webServiceContext.getMessageContext();
- Map httpHeaders = (Map) messageContext.get(MessageContext.HTTP_REQUEST_HEADERS);
- List userList = (List) httpHeaders.get(BindingProvider.USERNAME_PROPERTY);
- List passwordList = (List) httpHeaders.get(BindingProvider.PASSWORD_PROPERTY);
- if (userList == null || passwordList == null) {
- return false;
- }
- if (userList.size() != 1 || passwordList.size() != 1) {
- return false;
- }
- String username = userList.get(0).toString();
- String password = passwordList.get(0).toString();
- System.out.println(username);
- System.out.println(password);
- return ownerDao.areCredentialsValid(username, password);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement